Reputation: 11804
I am using double[] instead of NSArray. Would anyone know how to encode it for archiving
Upvotes: 2
Views: 208
Reputation: 3484
If you're not transferring the encoded data between platforms, where you might run into problems with endianness and data size, you can use
- (void)encodeBytes:(const uint8_t*)bytesp length:(NSUInteger)lenv forKey:(NSString*)key;
to store the bytes directly, and then
- (const uint8_t*)decodeBytesForKey:(NSString*)key returnedLength:(NSUInteger*)lengthp;
to decode them. As the NSCoder header file points out, the decodeBytesForKey:returnedLength: method returns immutable bytes, so you'll want to copy the returned array into your malloced double array. Since the returned array is const, I'm assuming the decoder owns that array and will free it when the decoder is dealloced.
This isn't as convenient as just putting the array into an NSData object and archiving that, but it does avoid the overhead of creating a temporary object.
Upvotes: 0
Reputation: 243156
Two options come to mind:
NSArray
of NSNumber
objects.NSValue
or NSData
object.Upvotes: 1