• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: initialize a store with default data core data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: initialize a store with default data core data


  • Subject: Re: initialize a store with default data core data
  • From: Gustavo Pizano <email@hidden>
  • Date: Thu, 21 Jan 2010 15:24:23 +0100

Hello, this is what Im doing now... I mistake before... is it ok if I do what Im doing here?


if(url){
		managedObjectContext = [[NSManagedObjectContext alloc] init];
		[managedObjectContext setPersistentStoreCoordinator:persistentStoreCoordinator];

		NSString * pListPath = [[NSBundle mainBundle] pathForResource:@"Status" ofType:@"plist"];
		NSDictionary * statusDic = [[NSDictionary alloc] initWithContentsOfFile:pListPath];
		NSEnumerator * enume = [statusDic keyEnumerator];
		id  key;
		while(key =  [enume nextObject]){ //Iterate the enumerator to set teh InvoiceStatus
			Status * stat = [NSEntityDescription insertNewObjectForEntityForName:@"Status" inManagedObjectContext:managedObjectContext];
			NSDictionary * internalDic = [statusDic valueForKey:(NSString*)key];
			...
			...
		}

		[statusDic release];  //REleasing the Dictionary
	}

On Jan 21, 2010, at 2:38 PM, Gustavo Pizano wrote:

> Hello.
> I was reading the Apple docs, and in the FAQ it says that I must check for :
>
>
> f you are using a non-document-based application and started with the standard application template then after these lines of code:
>
> if ( ![fileManager fileExistsAtPath:applicationSupportFolder isDirectory:NULL] )
> {
>     [fileManager createDirectoryAtPath:applicationSupportFolder attributes:nil];
> }
> url = [NSURL fileURLWithPath: [applicationSupportFolder stringByAppendingPathComponent: @"Delete.xml"]];
> you can add a check to determine whether the file at the url exists. If it doesn't, you need to import the data.
>
>
> now I have the following:
>
> if ( ![fileManager fileExistsAtPath:applicationSupportDirectory isDirectory:NULL] ) {
> 		if (![fileManager createDirectoryAtPath:applicationSupportDirectory withIntermediateDirectories:NO attributes:nil error:&error]) {
>             NSAssert(NO, ([NSString stringWithFormat:@"Failed to create App Support directory %@ : %@", applicationSupportDirectory,error]));
>             NSLog(@"Error creating application support directory at %@ : %@",applicationSupportDirectory,error);
>             return nil;
> 		}
>     }
>
>     NSURL *url = [NSURL fileURLWithPath: [applicationSupportDirectory stringByAppendingPathComponent: @"iZivnostData"]];
> 	//The iZivnostData doesn't exists, so Im gonna import the status
> 	if(url){
> 		NSString * pListPath = [[NSBundle mainBundle] pathForResource:@"Status" ofType:@"plist"];
> 		NSDictionary * statusDic = [[NSDictionary alloc] initWithContentsOfFile:pListPath];
> 		NSEnumerator * enume = [statusDic keyEnumerator];
> 		id  key;
> 		while(key =  [enume nextObject]){ //Iterate the enumerator to set teh InvoiceStatus
> 			//Status * stat = [NSEntityDescription entityForName:@"Status" inManagedObjectContext:mom];
> 			//NSDictionary * internalDic = [statusDic valueForKey:(NSString*)key];
> 		}
>
> 		[statusDic release];  //REleasing the Dictionary
> 	}
>     persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: mom];
> 	//Handling autoversioning
> 	NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
> 							 [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
> 							 [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
>
>     if (![persistentStoreCoordinator addPersistentStoreWithType:NSXMLStoreType
>                                                 configuration:nil
>                                                 URL:url
>                                                 options:options
>                                                 error:&error]){
>         [[NSApplication sharedApplication] presentError:error];
>         [persistentStoreCoordinator release], persistentStoreCoordinator = nil;
>         return nil;
>     }
>
>     return persistentStoreCoordinator;
>
> What is in bold is where I read the plist file and if I understand fine I can import the new data.. BUT ... as you can  see I commented  the internal while loop, because I need to have a NSManagedObjectContext, which at this point I don't have.. .. I dunno what I did'nt get form the docs..
> what am I missing to do.. ? If I call the [self managedObjectContext] method, this method will as for the persistentStorCoordinator which at this point it doesn't exist yet...  what to do  then?
>
>
> Best regards
>
> thanks a lot.
>
> Gustavo Pizano

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >initialize a store with default data core data (From: Gustavo Pizano <email@hidden>)

  • Prev by Date: Re: NSPredicateEditor Continuous updating failes
  • Next by Date: NSHost and NSStream question
  • Previous by thread: initialize a store with default data core data
  • Next by thread: NSHost and NSStream question
  • Index(es):
    • Date
    • Thread