Wednesday, April 11, 2012

Cocoa - Where does NSCoding save?

what is the default saving location of NSCoding protocol?


Also, is there any way to change such a default location to say, the folder where the .app file is located?



Answer:

You can directly write your encoded object data encoded according NSCoding to a file using NSKeyedArchiver
Like this:
BOOL result = [NSKeyedArchiver archiveRootObject:yourObject toFile:filename];
With filename you can choose your file location (you may set it to the documents directory if you are on iOS).
EDIT 1: If you'd like to store in into NSUserDefault... do:
NSData *yourObjectAsNSData = [NSKeyedArchiver archivedDataWithRootObject:yourObject];
[[NSUserDefaults standardUserDefaults] setObject:yourObjectAsNSData forKey:@"aKey"]

No comments:

Post a Comment