I spent the last few hours trying to figure it out, but I ran out of ideas.
All I'm trying to do is archive the object, but the archiveRootObject method continues to return NO
Here is my code:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSString *cacheDirectory = [paths objectAtIndex:0]; cacheDirectory = [cacheDirectory stringByAppendingPathComponent:@"MyAppCache"]; NSString *fullPath = [cacheDirectory stringByAppendingPathComponent:@"archive.data"]; if(![[NSFileManager defaultManager] fileExistsAtPath:fullPath]){ [[NSFileManager defaultManager] createDirectoryAtPath:fullPath withIntermediateDirectories:YES attributes:nil error:nil]; } NSArray *array = [NSArray arrayWithObjects:@"hello", @"world", nil]; NSLog(@"Full Path: %@", fullPath); BOOL res = [NSKeyedArchiver archiveRootObject:array toFile:fullPath]; if(res){ NSLog(@"YES"); }else{ NSLog(@"NO"); }
Every time I run this, it prints NO .
Any help would be appreciated!
source share