small medium large xlarge

Back to: All Forums  Core Data
Generic-user-small
30 Dec 2009, 18:45
Ward Ruth (1 post)

I’m somewhat of a cocoa newbie, and found the instructions for using the Info.plist to populate the Type table somewhat cryptic. But, after some digging around I succeeded in adding a RecipeTypes dictionary to the “Grokking_Recipes-Info.plist” file. In adding the key value pairs for this dictionary, it seemed to me that I should be adding entries such as “meat” and “Meat” for instance under the “Key” and “Value” columns in the plist graphical editor in XCode. But doing this I needed to modify the code snippet you provided on page 59 thusly:

	// the types table has not been populated
	NSDictionary *types;
	types = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"RecipeTypes"];
	
	for (id key in types) {
		NSManagedObject *object = [NSEntityDescription insertNewObjectForEntityForName:@"Type" 
																inManagedObjectContext:managedObjectContext];
		
		[object setValue:[types objectForKey:key] forKey:@"name"];
	}

Am I missing something, or does this make sense? The documentation seems to suggest that this approach would help in setting up for localization (using the same keys in the strings plist per locale).

Thanks for the book, using it as a refresher after delving into CoreData some last year. Further hints such as the above could help grease the skids for newbies such as myself, but I can understand trying to keep the book terse and targeted at knowledgeable developers as well. Always a good exercise to dig around and figure things out for oneself :-)

Avatarsmall_pragsmall
31 Dec 2009, 20:31
Marcus S. Zarra (284 posts)

I would suggest downloading the source code that is provided and you will see that the Info.plist is storing the types in an array instead of a dictionary:

  <key>RecipeTypes</key>
  <array>
    <string>Appetizer</string>
    <string>Salad</string>
    <string>Soup</string>
    <string>Dessert</string>
    <string>Fish</string>
    <string>Entrée</string>
    <string>Meat</string>
    <string>Cheese</string>
  </array>

</code>

You must be logged in to comment