Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-25-2010, 06:52 AM   #1 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 33
DevSdk is on a distinguished road
Default Simple curiosity - Code Data Recipe sample

In the Core Data Recipe sample, where are the categories list (Snack, Appetizer, etc) actually stored?

This is the code in the TypeSelectionViewController, where it gets the recipeTypes array, which is then used to populate the tableview:

Code:
    [super viewWillAppear:animated];
    
	// Fetch the recipe types in alphabetical order by name from the recipe's context.
	NSManagedObjectContext *context = [recipe managedObjectContext];
	
	NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
	[fetchRequest setEntity:[NSEntityDescription entityForName:@"RecipeType" inManagedObjectContext:context]];
	NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
	NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:&sortDescriptor count:1];
	[fetchRequest setSortDescriptors:sortDescriptors];
	
	NSError *error = nil;
	NSArray *types = [context executeFetchRequest:fetchRequest error:&error];
	self.recipeTypes = types;
	
	[fetchRequest release];
	[sortDescriptor release];
	[sortDescriptors release];
But where I can change them?
DevSdk is offline   Reply With Quote
Old 09-13-2010, 10:09 PM   #2 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 40
shiyue is on a distinguished road
Default

Hey, I'm learning this demo and got the same question, any help?
Thanks a lot!


Quote:
Originally Posted by DevSdk View Post
In the Core Data Recipe sample, where are the categories list (Snack, Appetizer, etc) actually stored?

This is the code in the TypeSelectionViewController, where it gets the recipeTypes array, which is then used to populate the tableview:

Code:
    [super viewWillAppear:animated];
    
	// Fetch the recipe types in alphabetical order by name from the recipe's context.
	NSManagedObjectContext *context = [recipe managedObjectContext];
	
	NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
	[fetchRequest setEntity:[NSEntityDescription entityForName:@"RecipeType" inManagedObjectContext:context]];
	NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
	NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:&sortDescriptor count:1];
	[fetchRequest setSortDescriptors:sortDescriptors];
	
	NSError *error = nil;
	NSArray *types = [context executeFetchRequest:fetchRequest error:&error];
	self.recipeTypes = types;
	
	[fetchRequest release];
	[sortDescriptor release];
	[sortDescriptors release];
But where I can change them?
shiyue is offline   Reply With Quote
Old 09-15-2010, 09:59 AM   #3 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 33
DevSdk is on a distinguished road
Default

Well this is old. Anyway, If you look at the app delegate, you'll find this code:


Code:
/*
	 Set up the store.
	 For the sake of illustration, provide a pre-populated default store.
	 */
	NSFileManager *fileManager = [NSFileManager defaultManager];
	// If the expected store doesn't exist, copy the default store.
	if (![fileManager fileExistsAtPath:storePath]) {
		NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"Recipes" ofType:@"sqlite"];
		if (defaultStorePath) {
			[fileManager copyItemAtPath:defaultStorePath toPath:storePath error:NULL];
		}
	}
So, it's actually loading the sqlite file to prepopulate the store if there's no data.
DevSdk is offline   Reply With Quote
Old 09-21-2010, 03:09 AM   #4 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 551
aldcorn@live.com is on a distinguished road
Default How can you change this data.

This array is readonly. Is there a way to change this list of items.

Quote:
Originally Posted by DevSdk View Post
Well this is old. Anyway, If you look at the app delegate, you'll find this code:


Code:
/*
	 Set up the store.
	 For the sake of illustration, provide a pre-populated default store.
	 */
	NSFileManager *fileManager = [NSFileManager defaultManager];
	// If the expected store doesn't exist, copy the default store.
	if (![fileManager fileExistsAtPath:storePath]) {
		NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"Recipes" ofType:@"sqlite"];
		if (defaultStorePath) {
			[fileManager copyItemAtPath:defaultStorePath toPath:storePath error:NULL];
		}
	}
So, it's actually loading the sqlite file to prepopulate the store if there's no data.
aldcorn@live.com is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 343
9 members and 334 guests
2Apps1Day, akacaj, c2matrix, esoteric, givensur, mjnafjke, Pudding, SLIC, Techgirl-52
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,650
Threads: 94,115
Posts: 402,887
Top Poster: BrianSlick (7,990)
Welcome to our newest member, soohyun
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:10 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0