views:

36

answers:

2

Does NSMutableArray support recursive serialization? E.g. will a NSMutableArray of NSMutableArray's serialize the entirety of the heirarchy out when calling writeToFile?

Example:

NSMutableArray *topArray = [[NSMutableArray alloc] init];
NSMutableArray *bottomArray = [[NSMutableArray alloc] init];

NSString *foo = @"foo";
NSString *bar = @"bar";
NSString *bar2 = @"bar2";

[topArray addObject:foo];
[topArray addObject:bottomArray];

[bottomArray addObject:bar];
[bottomArray addObject:bar2];

[topArray writeToFile:validFilePath atomically:YES];

I am asking as I have 3 string values and an NSMutableArray of NSData objects that I want to stuff into a parent NSMutableArray and serialize out to a file and then reconstitute at a later time. I would like to do this without writing my own NSCoder implementation if possible, take the easy way out.

Thanks.

A: 

From experience I can say that any objects that I've added to an array are indeed recursively added to the file that is written out.

Although its such an easy thing to test you might as well run that code you've written to test it yourself!

James Raybould
Your answer was faster than me writing code (which i did anyway), and as I had hoped :). I wrote a small app and asserted this is true - you were correct. Thanks!
sanderb