从plist读取对象到NSArray

时间:2022-09-24 23:12:56

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?

我想有一个NSMutableArray的病人,但是我不想硬编码的病人信息(姓名,dob,等等)。我想把它存储在一个plist中然后可以有一个NSArray of Patients对象。我该怎么做呢?我知道如果它只是NSString数组该怎么做,但如果它是对象的NSArray呢?

1 个解决方案

#1


6  

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. If you want more control, you can work with sqlite and if you do, fmdb is a good wrapper class.

CoreData将提供一个设计器来设计您的逻辑对象,并为您处理sqlite的持久性。如果您想要更多的控制,您可以使用sqlite,如果您这样做,fmdb是一个很好的包装类。

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中跟踪病人。如果是这样,那么这是另一篇关于持久化数组的文章:

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

希望这有助于

#1


6  

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. If you want more control, you can work with sqlite and if you do, fmdb is a good wrapper class.

CoreData将提供一个设计器来设计您的逻辑对象,并为您处理sqlite的持久性。如果您想要更多的控制,您可以使用sqlite,如果您这样做,fmdb是一个很好的包装类。

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中跟踪病人。如果是这样,那么这是另一篇关于持久化数组的文章:

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

希望这有助于