简体   繁体   中英

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). 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?

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 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.

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:

How to read data structure from .plist file into NSArray

From that post:

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

Hope that helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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