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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to