iphone - 序列化一个包含对象的 NSMutableArray

标签 iphone ios ipad serialization ios4

我有一个 NSMutableArray,里面有一堆点(这是我定义的一个类)。我想序列化这个 NSMutableArray 以保存到我的磁盘。如果我在我的类 Point 中实现 NSCoding 协议(protocol),是否可以直接在我的 NSMutableArray 中使用 NSKeyedArchiver?

就像这个例子:

NSMutableData *data = [NSMutableData new];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeObject:myArray forKey:@"array"];
[data writeToFile:filename attomically:YES];
[archiver release];
[data release];

最佳答案

是的,这是可能的,引用 Apple documentation :

The NSArray class adopts the NSCopying, NSMutableCopying, and NSCoding protocols;

请注意,如果您正在使用,也许您应该使用 Apple CGPoint 结构,它带有许多方便的实用程序:CGPointFromStringNSStringFromCGPoint see Apple documentation for more information

还有这些你可能感兴趣的CGPointEqualToPoint, CGRectContainsPoint, CGRectIntersectsRect or CGRectContainsRect... see Apple documentation for more information

关于iphone - 序列化一个包含对象的 NSMutableArray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5515621/

相关文章:

iphone - 使用Unity引擎在iPhone上开发游戏

ios - 在 Xcode 中生成无限数量的对象

ios - 当我在 iPhone 模拟器上运行时,为什么我的 iPhone/iPad 应用程序顶部有一个黑条?

iphone - 如何获取YouTube视频网址

iphone - 在 IOS 6 中设置 UITableView 的背景颜色

iphone - UIManagedDocument 和 NSFetchedResultsController

iphone - "UIStatusBarStyleBlackTranslucent is not available on this device. Ignoring UIStatusBarStyle key in Info.plist."- 该怎么办?

ipad - 点击事件在 iPad 上不起作用

iphone - 如何使用NSScanner解析.ics文件

ios - 如何将 Swift 中的文本格式设置为底部?