简体   繁体   中英

Is NSMutableArray writeToFile recursive?

Does NSMutableArray support recursive serialization? Eg 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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM