1

Can i decode and encode an array in ths way??

NSMutableArray *arr;

-(void)encodeWithCoder:(NSCoder*)coder 
{ 
   [coder encodeInt:arr forKey:@"Array"]; 
} 

-(id)initWithCoder:(NSCoder*)decoder 
{ 
   NSMutableArray array;
   array = [[decoder decodeIntForKey:@"Array"]copy]; 
   return self; 
} 

1 Answer 1

1

It will not encode/decode the NSMutableArray that way.

If objects in your array implement NSCoding protocol then you can encode array by calling:

NSMutableArray * myMutableArray = ...
NSData* myData = [NSKeyedArchiver archivedDataWithRootObject:myMutableArray];

And reverse with:

NSMutableArray* myMutableArray = [NSKeyedUnarchiver
                                             unarchiveObjectWithData:myData];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.