NSCoding protocol
NSCoding protocol
- Subject: NSCoding protocol
- From: email@hidden
- Date: Fri, 3 Oct 2008 12:00:19 -0700
I want MyClass to conform to the NSCoding protocol. But I'm puzzled
about how to implement the initWithCoder: method.
Suppose I have this in MyClass.h:
NSString *S1, *S2, *S3;
and this in its init function:
S1 = @"a string";
S2 = [[NSString alloc] init];
S3 = [NSString string];
So to conform to the protocol, I'd have something like this in
MyClass.m too:
- (id)initWithCoder:(NSCoder *)decoder {
self = [super init];
S1 = [decoder decodeObjectForKey:@"S1"];
S2 = [[decoder decodeObjectForKey:@"S2"] retain];
S3 = [[decoder decodeObjectForKey:@"S3"] retain];
return self;
}
(I'm not posting the encodeWithCoder: method.)
So finally, my question: am I right to retain S2 and S3, and not S1?
_______________________________________________
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