从plist到NSArray读取对象 [英] reading objects from plist to NSArray

查看:93
本文介绍了从plist到NSArray读取对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有一个NSMutableArray患者,但我不想硬编码患者信息(姓名,dob等)。我想将它存储在plist中,然后能够拥有一个NSArray of Patients对象。我怎样才能做到这一点?我知道如果它只是一个NSString数组怎么办,但如果它是一个NSArray对象呢?

I wanted to have an NSMutableArray of patients, however I don't want to hard code the patients info (name, dob, etc). I want to store that in a plist and then be able to have an NSArray of Patients object. How can I do this? I know how to do if it's just an NSString array, but what if it's an NSArray of objects?

推荐答案

如果你是存储和检索患者列表,然后随着您的应用程序成熟,您可能需要以各种方式访问​​它们。 CoreData和/或Sqlite提供了更强大的存储机制,可提供丰富的查询,索引和CRUD操作。

If you're storing and retrieving a list of patients, then over time as your app matures you will likely need to access them in various ways. CoreData and/or Sqlite offer more robust storage mechanisms that offer rich querying, indexing and CRUD operations.

CoreData将为设计人员设计逻辑对象并负责坚持为你sqlite。如果你想要更多的控制,你可以使用sqlite,如果你这样做,fmdb是一个很好的包装类。

CoreData will offer a designer to design your logical objects and take care of the persistance to sqlite for you. If you want more control, you can work with sqlite and if you do, fmdb is a good wrapper class.

除非你这样做是学习的学习样本plists,我不建议跟踪患者。如果是这种情况,那么这是另一篇关于将数组保持为plists的SO文章:

Unless you're doing this as a learning sample to learn plists, I wouldn't recommend tracking patients in a plist. If that's the case, then here's another SO article on persisting arrays to plists:

如何从.plist文件读取数据结构到NSArray

来自那篇文章:

NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"league" ofType:@"plist"];
contentArray = [NSArray arrayWithContentsOfFile:plistPath];

希望有所帮助

这篇关于从plist到NSArray读取对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆