开发者

Is NSMutableArray writeToFile recursive?

Does NSMutableArray support recursive serialization? E.g. will a NS开发者_开发问答MutableArray 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.


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!


You should take a look at the API reference: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/doc/uid/20000137-BABCGEFF

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜