开发者

How can I pull data from a plist by name?

I currently have an entity Exercise with attributes name, picture , muscle, etc.

When an exercise object is created and saved in my app (using core data), all these attributes are set from a dictionary in a .plist. I now want to add de开发者_运维知识库scriptions (paragraph of text) but it doesn't make sense to add a description attribute to Exercise because there will be several of the same exercises and this may just waste space.

Is there a way I can create a new class, maybe exerciseDescription, that pulls the exercise name attribute from the selected exercise, and pull the corresponding description from a .plist?

I have almost 300 exercises and the plist I am currently pulling info from is an array of dictionarys for each muscle group which have an array of exercises in each.


Could you create a new plist called ExerciseDescriptions.plist

How can I pull data from a plist by name?

Then implement something like this. (I've not tested this code, it's just off my head)

NSString *exerciseName = [exerciseEntity valueForKey:@"name"];

NSString *path = [[NSBundle mainBundle] pathForResource:@"ExerciseDescriptions" ofType:@"plist"];

NSDictionary *exerciseDescription = [NSDictionary dictionaryWithContentsOfFile:path];
NSString *description = [exerciseDescription objectForKey:exerciseName];


One simple way is to create a (unique) file for each exercise description and store its handle (path?) in all cooresponding Exercise objects.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜