how to use NSCoder for transfer images and strings together over bluetooth?

1.1k Views Asked by At

I want to use NSCoder and transfer NSString and UIImage with single NSData over bluetooth

you can simply say, "I want to sent NSData over bluetooth which contains UIImage and NSString"

Help me out,,,

It is very complex question, and I am stuck here since two days :-(

1

There are 1 best solutions below

0
On BEST ANSWER

Create a objective-c class with propertys NSString and UIImage
Than you need to implement

 -(void) encodeWithCoder: (NSCoder *) encoder
{
[super encodeWithCoder:encoder];
[encoder encodeObject: [self yourString] forKey:@"string"];
[encoder encodeObject: [self yourImage] forKey:@"image"];
}

-(id) initWithCoder: (NSCoder *) decoder
{
[super initWithCoder:decoder]; 
self.yourString = [decoder decodeObjectForKey:@"string"];
self.yourImage = [decoder decodeObjectForKey:@"image"];

return self;
}

now the problem is, that UIImage doesn't implement encodeWithCoder the solution can you find here: Archiving UIImages with NSCoder