Saving NSArray of custom objects
Saving NSArray of custom objects
- Subject: Saving NSArray of custom objects
- From: DKJ <email@hidden>
- Date: Mon, 13 Jul 2009 17:22:36 -0700
I've defined my own MyClass and made it conform to the NSCoding
protocol by adding methods like this:
- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeInt:index forKey:@"index"];
}
- (id)initWithCoder:(NSCoder *)decoder
{
self = [super init];
index = [decoder decodeIntForKey:@"index"];
return self;
}
I then put a bunch of these into an NSArray and try to save the array
like this:
NSString *path = [NSHomeDirectory()
stringByAppendingPathComponent:FILE_PATH];
BOOL didIt = [theArray writeToFile:path atomically:NO];
But nothing is saved: didIt = 0.
I must be missing a step somewhere. I've been looking at "Archives and
Serializations Programming Guide for Cocoa", and finding it rather
bewildering. A nudge in the right direction would be much appreciated.
dkj
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden