NSMutableArray writeToFile 是递归的吗?
NSMutableArray 支持递归序列化吗?例如,当调用 writeToFile 时,NSMutableArray 的 NSMutableArray 会序列化整个层次结构吗?
示例:
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];
我问,因为我有 3 个字符串值和一个 NSData 对象的 NSMutableArray,我想将它们填充到父 NSMutableArray 中并序列化到文件中,然后稍后重新构建。如果可能的话,我想在不编写自己的 NSCoder 实现的情况下执行此操作,采取简单的方法。
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据经验,我可以说我添加到数组中的任何对象确实会递归地添加到写出的文件中。
尽管测试起来很容易,但您最好运行您编写的代码来亲自测试它!
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!
您应该查看 API 参考: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/doc/ uid/20000137-BABCGEFF
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