• 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
Re: encoding objects containing NSData ivars using NSKeyedArchiver
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: encoding objects containing NSData ivars using NSKeyedArchiver


  • Subject: Re: encoding objects containing NSData ivars using NSKeyedArchiver
  • From: Jens Alfke <email@hidden>
  • Date: Wed, 12 Mar 2008 09:14:24 -0700


On 12 Mar '08, at 7:44 AM, Daniel Thorpe wrote:

I'm trying to archive an object using NSKeyedArchiver. The object is question has quite a complex structure, and one of it's instance variables is an NSMutableData. I've tried using
[coder encodeObject:result forKey:@"TchebichefMoment_momentData"];
which doesn't seem to do anything at all

Really? That should work fine. I've encoded NSData objects like this many times, so I'm pretty sure there's not a bug in NSKeyedArchiver. Have you set a breakpoint and verified that 'result' is non-nil when this is called?


const double *dataPtr = (const double *)[result bytes];
[coder encodeBytes:dataPtr length:(NSUInteger)(N*N*sizeof(double)) forKey:@"TchebichefMoment_momentData"];

...

NSUInteger len;
const double *dataPtr = (const double *)[coder decodeBytesForKey:@"TchebichefMoment_momentData" returnedLength:&len];
self.result = [[NSData alloc] initWithBytes:dataPtr length:len];

This should work too, although if the array is very large it may use more memory, because the archiver keeps its own copy of the returned data block.


—Jens

PS: There's no need to prefix the key strings with a namespace, e.g. "TchebichefMoment_". The keys are specific to each object. You just shouldn't use a name that's also used by a superclass.

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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

References: 
 >encoding objects containing NSData ivars using NSKeyedArchiver (From: Daniel Thorpe <email@hidden>)

  • Prev by Date: BitMap data format and autorelease
  • Next by Date: NSAffineTransform & bezier path line widths
  • Previous by thread: encoding objects containing NSData ivars using NSKeyedArchiver
  • Next by thread: Where are the system spellchecker prefs stored?
  • Index(es):
    • Date
    • Thread