从 NSMutableArray 更改为 .plist
我已经完成了几个关于 uitableviews 的教程。
我已按照指示将所有信息放入“listofitems”中,如下所示,
listOfItems = [[NSMutableArray alloc] init];
NSArray *countriesToLiveInArray = [NSArray arrayWithObjects:@"Iceland", @"Greenland", @"Switzerland", @"Norway", @"New Zealand", @"Greece", @"Rome", @"Ireland", nil];
NSDictionary *countriesToLiveInDict = [NSDictionary dictionaryWithObject:countriesToLiveInArray forKey:@"Countries"];
NSArray *countriesLivedInArray = [NSArray arrayWithObjects:@"India", @"U.S.A", nil];
NSDictionary *countriesLivedInDict = [NSDictionary dictionaryWithObject:countriesLivedInArray forKey:@"Countries"];
[listOfItems addObject:countriesToLiveInDict];
[listOfItems addObject:countriesLivedInDict];
这将创建一个分区表视图。我想知道如何将其更改为 .plist,而不是将其全部输入到 RootViewController.m 中。我仍然希望它处于分段表格视图中。
有没有一种简单的方法可以从 NSMutableArray、NSArray 和 NSDictionary 更改为 plist?
I have been working through several tutorials on uitableviews.
I have put, as instructed, all the info into a 'listofitems' as below
listOfItems = [[NSMutableArray alloc] init];
NSArray *countriesToLiveInArray = [NSArray arrayWithObjects:@"Iceland", @"Greenland", @"Switzerland", @"Norway", @"New Zealand", @"Greece", @"Rome", @"Ireland", nil];
NSDictionary *countriesToLiveInDict = [NSDictionary dictionaryWithObject:countriesToLiveInArray forKey:@"Countries"];
NSArray *countriesLivedInArray = [NSArray arrayWithObjects:@"India", @"U.S.A", nil];
NSDictionary *countriesLivedInDict = [NSDictionary dictionaryWithObject:countriesLivedInArray forKey:@"Countries"];
[listOfItems addObject:countriesToLiveInDict];
[listOfItems addObject:countriesLivedInDict];
This creates a sectioned table view. I would like to know how to change it into a .plist instead of typing it all out into the RootViewController.m. I would still like it to be in a sectioned tableview.
Is there a simple method for changing from this NSMutableArray,NSArray and NSDictionary to a plist?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
writeToFile:atomically: 有一个简单的方法:
这将自动创建一个包含 plist 的文件。
There's a simple method for this
writeToFile:atomically:
:This will automatically create a file with plist inside it.
这有点取决于你想要在 plist 中包含什么,以及你在其中放入什么。如果条目和内容都是 CFPropertyList 类型(CFString、CFDate、CFData、CFDictionary、CFArray、CFNumber...),则只需使用
CFPropertyListCreateDeepCopy
之类的内容创建它。如果您有不可转换的自定义对象(例如,您自己的 NSObject 子类),请参阅 cocoa 归档主题。
that sorta depends on what you want in a plist, and what you put into it. if the entries and contents are all CFPropertyList types (CFString,CFDate,CFData,CFDictionary,CFArray,CFNumber...) then just create it with something like
CFPropertyListCreateDeepCopy
.if you have non-convertible custom objects (e.g., your own NSObject subclasses), then see the cocoa archiving topics.
这是简单的函数结束听到相关化
这是函数正在更新 NSArray
This is the simple function end hear relization
This is function is updating NSArray