Hello guys... I am probably not seeing something here, that is why I am asking for help :) Here is the deal I have a NSMutable array of items that fulfill the NSCoding protocol, but NSKeyedArchiver always fails to archive it... here is my object implementation:
@implementation YTVideo
@synthesize URL,thumb,titulo;
#pragma mark NSCoding
#define kTituloKey @"titulo"
#define kURLKey @"URL"
#define kThumbKey @"thumb"
-(id)initWithData:(NSString *)ktitle :(UIImage *)kThumb :(NSURL *)kURL{
self.titulo = ktitle;
self.thumb = kThumb;
self.URL = kURL;
return self;
}
- (void) encodeWithCoder:(NSCoder *)encoder {
[encoder encodeObject:titulo forKey:kTituloKey];
[encoder encodeObject:URL forKey:kURLKey];
NSData *thumbData = UIImagePNGRepresentation(thumb);
[encoder encodeObject:thumbData forKey:kThumbKey];
}
- (id)initWithCoder:(NSCoder *)decoder {
NSString* ktitulo = [decoder decodeObjectForKey:kTituloKey];
NSURL* kURL = [decoder decodeObjectForKey:kURLKey];
NSData* kThumbdata = [decoder decodeObjectForKey:kThumbKey];
UIImage* kThumb=[UIImage imageWithData:kThumbdata];
return [self initWithData:ktitulo:kThumb:kURL];
}
@end
During the program execution I have a NSMutable array of those objects called videosArray.
then, eventually, I try:
NSString* path =[NSHomeDirectory() stringByAppendingPathComponent:@"teste.wrapit"];
NSLog(@"PATH =%@",path);
bool teste = [NSKeyedArchiver archiveRootObject:videosArray toFile:path];
NSLog(@"aramzenamento:%@",teste ? @"sucesso!" :@"Nope");
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:path];
NSLog(@"Arquivo armazenado existe?%@",fileExists ?@"Sim":@"Nao");
And I always get a fail on my boolean checks... Any Ideas where I am completely wrong?? Thanks!!