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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 08-11-2009, 11:45 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 3
Default LOAD DATA INTO CORE DATA??

Does anyone know how load data into Core Data easily? Preferably from a file that can be edited easily like a .CSV file or whatever else. Or should I be going about this another way?

Thanks!
Howell is offline   Reply With Quote
Old 08-11-2009, 02:15 PM   #2 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 5
Default

Quote:
Originally Posted by Howell View Post
Does anyone know how load data into Core Data easily? Preferably from a file that can be edited easily like a .CSV file or whatever else. Or should I be going about this another way?

Thanks!
Here is what I have done for my app.

1) Create the model in XCode (it is essential do this first, because XCode uses a specific naming convention and adds several underlying tables to the actual data model.

2) Run the application in the Simulator and with the app running ... go and copy the database (/users/library/Application Support/iPhone Simulator/User/Applications/<app name> to some other location

3) Open up the database (I use SQLite Manager plugin in Firefox)

4) From here I import my data from a CSV file once I have updated all of my CSV column names to match the table names

5) Look at the CoreDataRecipies sample code for including a pre-populated database (code is in the Delegate.m file)

6) Import the database in your application and you should be good to go.
mgwinthrop is offline   Reply With Quote
Old 10-12-2009, 02:00 AM   #3 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 10
Default I don't see the delegate.m in the CoreDataRecipies.

Hi,

This is something I'd like to do and your instructions seem clear but i can't find the delegate.m in corerecipies. can you post the links or code?

Thanks!

asUwish

Quote:
Originally Posted by mgwinthrop View Post
Here is what I have done for my app.

1) Create the model in XCode (it is essential do this first, because XCode uses a specific naming convention and adds several underlying tables to the actual data model.

2) Run the application in the Simulator and with the app running ... go and copy the database (/users/library/Application Support/iPhone Simulator/User/Applications/<app name> to some other location

3) Open up the database (I use SQLite Manager plugin in Firefox)

4) From here I import my data from a CSV file once I have updated all of my CSV column names to match the table names

5) Look at the CoreDataRecipies sample code for including a pre-populated database (code is in the Delegate.m file)

6) Import the database in your application and you should be good to go.
asUwish is offline   Reply With Quote
Old 10-28-2009, 12:01 PM   #4 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 32
Default

Looks like that code is in RecipesAppDelegate.m here:
Code:
/**
 Returns the persistent store coordinator for the application.
 If the coordinator doesn't already exist, it is created and the application's store added to it.
 */
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
	
    if (persistentStoreCoordinator != nil) {
        return persistentStoreCoordinator;
    }
		
	NSString *storePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"Recipes.sqlite"];
	/*
	 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];
		}
	}
	
	NSURL *storeUrl = [NSURL fileURLWithPath:storePath];
	
	NSError *error;
    persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];
    if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:nil error:&error]) {
		// Handle error
		NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
		exit(-1);  // Fail
    }    
		
    return persistentStoreCoordinator;
}
jazztpt is offline   Reply With Quote
Reply

Bookmarks

Tags
3.0, core data sqlite, data, iphone, xcode

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: 251
13 members and 238 guests
2WeeksToGo, AdamL, ADY, BrianSlick, Dani77, Dattee, headkaze, mer10, mgon987, timle8n1, Touchmint, vigu360
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,879
Threads: 89,228
Posts: 380,746
Top Poster: BrianSlick (7,129)
Welcome to our newest member, mgon987
Powered by vBadvanced CMPS v3.1.0

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