• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSCoding protocol
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: NSCoding protocol
      • From: Negm-Awad Amin <email@hidden>
    • Re: NSCoding protocol
      • From: Nick Zitzmann <email@hidden>
    • Re: NSCoding protocol
      • From: "Stephen J. Butler" <email@hidden>
  • Prev by Date: Re: Newbie: Simple display with NSView - problem
  • Next by Date: Multiples calls to acceptsFirstResponder
  • Previous by thread: cookies and UIWebView
  • Next by thread: Re: NSCoding protocol
  • Index(es):
    • Date
    • Thread