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

encoding objects containing NSData ivars using NSKeyedArchiver


  • Subject: encoding objects containing NSData ivars using NSKeyedArchiver
  • From: Daniel Thorpe <email@hidden>
  • Date: Wed, 12 Mar 2008 14:44:52 +0000

Hello everyone!

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, so I tried:

- (void)encodeWithCoder:(NSCoder *)coder {
	[super encodeWithCoder:coder];
	[coder encodeInteger:order forKey:@"TchebichefMoment_momentOrder"];
	[coder encodeObject:input forKey:@"TchebichefMoment_input"];
	[coder encodePoint:centre forKey:@"TchebichefMoment_centre"];

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


The result ivar is an NSMutableData object containing N^2 doubles. This compiles, and does archive something, however, when it get's decoded, the object is not the same.....

My decoding method is:

- (id)initWithCoder:(NSCoder *)coder {
if(self = [super initWithCoder:coder]) {
self.order = [coder decodeIntegerForKey:@"TchebichefMoment_momentOrder"];
input = [[coder decodeObjectForKey:@"TchebichefMoment_input"] retain];
self.width = [input pixelsWide];
self.height = [input pixelsHigh];
self.N = (width <= height) ? width : height;
self.half = (NSInteger)(N/2.0);
self.centre = [coder decodePointForKey:@"TchebichefMoment_centre"];


// self.result = [[coder decodeObjectForKey:@"TchebichefMoment_momentData"] retain];

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

[self initTchebichefPolynomial];
}
return self;
}


Any thoughts on how to do this properly, of if someone can confirm that this is correct, and there definitely isn't a bug in NSKeyedArchiver would be really appreciated!

Cheers
Dan



_______________________________________________

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: encoding objects containing NSData ivars using NSKeyedArchiver
      • From: Jens Alfke <email@hidden>
  • Prev by Date: Re: NSTableView + delete button?
  • Next by Date: Where are the system spellchecker prefs stored?
  • Previous by thread: Re: runtime error
  • Next by thread: Re: encoding objects containing NSData ivars using NSKeyedArchiver
  • Index(es):
    • Date
    • Thread