从 NSMutableArray 更改为 .plist

发布于 2024-10-11 16:47:04 字数 895 浏览 3 评论 0原文

我已经完成了几个关于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

芸娘子的小脾气 2024-10-18 16:47:04

writeToFile:atomically: 有一个简单的方法:

[listOfItems writeToFile:destinationPath atomically:YES];

这将自动创建一个包含 plist 的文件。

There's a simple method for this writeToFile:atomically::

[listOfItems writeToFile:destinationPath atomically:YES];

This will automatically create a file with plist inside it.

红墙和绿瓦 2024-10-18 16:47:04

这有点取决于你想要在 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.

夜空下最亮的亮点 2024-10-18 16:47:04

这是简单的函数结束听到相关化

这是函数正在更新 NSArray

- (void) WriteRecordToFile:(NSMutableDictionary*)countDict {
    // Here to write to file
    databasePathCallCount = @"plist path";
    NSMutableArray *countArray = [NSMutableArray arrayWithContentsOfFile:databasePathCallCount];
    if(countArray)
        [countArray addObject:countDict];
    [countArray writeToFile:databasePathCallCount atomically:NO];
}

This is the simple function end hear relization

This is function is updating NSArray

- (void) WriteRecordToFile:(NSMutableDictionary*)countDict {
    // Here to write to file
    databasePathCallCount = @"plist path";
    NSMutableArray *countArray = [NSMutableArray arrayWithContentsOfFile:databasePathCallCount];
    if(countArray)
        [countArray addObject:countDict];
    [countArray writeToFile:databasePathCallCount atomically:NO];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文