• 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
Question about direct vs accessor use with (init & encode ...WithCoder)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Question about direct vs accessor use with (init & encode ...WithCoder)


  • Subject: Question about direct vs accessor use with (init & encode ...WithCoder)
  • From: Michael de Haan <email@hidden>
  • Date: Sun, 25 Oct 2009 00:20:29 -0700

Surprisingly, I could find no reference to this issue.

In the archives, there seems to be, lately, the consensus ( I hope) that direct ivar access is preferred in 2 methods ie init and dealloc.


This would seem to imply that initWithCoder/encodeWithCoder should also use direct ivar access,   but I have seen **both** used in reputable sources.

So, from Apple's docs on archiving this:


- (void)encodeWithCoder:(NSCoder *)coder {
    [super encodeWithCoder:coder];
    [coder encodeObject:mapName forKey:@"MVMapName"];
    [coder encodeFloat:magnification forKey:@"MVMagnification"];
    [coder encodeObject:legendView forKey:@"MVLegend"];
    [coder encodeConditionalObject:auxiliaryView forKey:@"MVAuxView"];
}



and from the  binding examples on mmalc's page, this: ( I understand that the method is deprecated)

- (NSData *)dataRepresentationOfType:(NSString *)aType 
{
           // create an archive of the collection and its attributes
    NSKeyedArchiver *archiver;
    NSMutableData *data = "">NSMutableData data];

    archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];

    [archiver encodeObject:self.name forKey:@"name"];

    [archiver encodeObject:self.collectionDescription forKey:@"collectionDescription"];
    [archiver encodeObject:self.collection forKey:@"collection"];


    [archiver finishEncoding];


    return data;

}


Is this just 6 of one and half dozen of the other?

Thanks.



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: ostringstream problem with numbers
  • Next by Date: Question about direct vs accessor....PLEASE IGNORE...WILL NOT HAPPEN AGAIN :-) ..APOLOGIES
  • Previous by thread: Re: Prevent dsymutil from running at the end of a release build?
  • Next by thread: Question about direct vs accessor....PLEASE IGNORE...WILL NOT HAPPEN AGAIN :-) ..APOLOGIES
  • Index(es):
    • Date
    • Thread