Re: encoding objects containing NSData ivars using NSKeyedArchiver
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