简体   繁体   English

从plist到NSArray读取对象

[英]reading objects from plist to NSArray

I wanted to have an NSMutableArray of patients, however I don't want to hard code the patients info (name, dob, etc). 我希望有一个NSMutableArray患者,但我不想硬编码患者信息(名称,dob等)。 I want to store that in a plist and then be able to have an NSArray of Patients object. 我想将它存储在plist中,然后能够拥有一个NSArray of Patients对象。 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? 我知道怎么做,如果它只是一个NSString数组,但如果它是一个NSArray对象怎么办?

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提供了更强大的存储机制,可提供丰富的查询,索引和CRUD操作。

CoreData will offer a designer to design your logical objects and take care of the persistance to sqlite for you. CoreData将为设计人员设计逻辑对象,并为您提供持久的sqlite。 If you want more control, you can work with sqlite and if you do, fmdb is a good wrapper class. 如果你想要更多的控制,你可以使用sqlite,如果你这样做,fmdb是一个很好的包装类。

Unless you're doing this as a learning sample to learn plists, I wouldn't recommend tracking patients in a plist. 除非您将此作为学习样本的学习样本,否则我不建议您使用plist来跟踪患者。 If that's the case, then here's another SO article on persisting arrays to plists: 如果是这种情况,那么这是关于将数组持久化到plists的另一篇SO文章:

How to read data structure from .plist file into NSArray 如何从.plist文件读取数据结构到NSArray

From that post: 从那篇文章:

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

Hope that helps 希望有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM