• 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
Saving NSArray of custom objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Saving NSArray of custom objects
      • From: Mike Abdullah <email@hidden>
    • Re: Saving NSArray of custom objects
      • From: Jonathan Hess <email@hidden>
  • Prev by Date: Re: Printing a View
  • Next by Date: Re: Saving NSArray of custom objects
  • Previous by thread: Re: AVAudioplayer is skipping -- sounds like a cd skipping
  • Next by thread: Re: Saving NSArray of custom objects
  • Index(es):
    • Date
    • Thread