objective c - How to add CoreData to exisiting Tab Based IOS project -


i have tried lot of different answers, can't seem work. trying add core data existing tab based project have. added core data framework through targets, set datamodel , entities correctly, can't seem access it. have gotten many different errors, recent is:

*** terminating app due uncaught exception 'nsinvalidargumentexception', reason: 'cannot create nspersistentstorecoordinator nil model' 

i set new utility based project using preset core data , copied code directly. changed file url name current project , doesn't work. here code:

appdelegate.h

#import <uikit/uikit.h>  @interface appdelegate : uiresponder <uiapplicationdelegate> { bool isnotfirsttime; nsmutablearray *teammembers; nsmutablearray *projects; nsmutablearray *tasks;   } @property(readwrite, retain) nsmutablearray *teammembers; @property(readwrite, retain) nsmutablearray *projects; @property(nonatomic, retain) nsmutablearray *tasks; @property(nonatomic)bool isnotfirsttime; @property (strong, nonatomic) uiwindow *window;  @property (readonly, strong, nonatomic) nsmanagedobjectcontext *managedobjectcontext; @property (readonly, strong, nonatomic) nsmanagedobjectmodel *managedobjectmodel; @property (readonly, strong, nonatomic) nspersistentstorecoordinator    *persistentstorecoordinator;  - (void)savecontext; - (nsurl *)applicationdocumentsdirectory; - (nsurl *)applicationdocumentsdirectory; - (void)savecontext;  @end 

appdelegate.m reason when create file url remains null.....i have no idea why..

    #import "appdelegate.h"     #import "task.h"     #import "project.h"      #import "teammember.h"     #import "newteammemberwindow.h"       @implementation appdelegate      @synthesize window = _window;     @synthesize tasks;     @synthesize teammembers;     @synthesize projects; @synthesize isnotfirsttime; @synthesize managedobjectcontext = __managedobjectcontext; @synthesize managedobjectmodel = __managedobjectmodel; @synthesize persistentstorecoordinator = __persistentstorecoordinator;    - (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {       nsmanagedobjectcontext *context = [self managedobjectcontext];     if (!context) {         nslog(@"no context on app load");     }      newteammemberwindow *newteammemberwindowobject = [[newteammemberwindow alloc]init];     newteammemberwindowobject.managedobjectcontext = context;           return yes;      } 

//removed normal methods consolidate code on stack overflow

#pragma mark - core data stack  /**  returns managed object context application.  if context doesn't exist, created , bound persistent store coordinator application.  */ - (nsmanagedobjectcontext *)managedobjectcontext {     if (__managedobjectcontext != nil)     {         return __managedobjectcontext;     }      nspersistentstorecoordinator *coordinator = [self persistentstorecoordinator];     if (coordinator != nil)     {         __managedobjectcontext = [[nsmanagedobjectcontext alloc] init];         [__managedobjectcontext setpersistentstorecoordinator:coordinator];     }     return __managedobjectcontext; }  /**  returns managed object model application.  if model doesn't exist, created application's model.  */ - (nsmanagedobjectmodel *)managedobjectmodel {     if (__managedobjectmodel != nil)     {         return __managedobjectmodel;     } 

this part modelurl remains null.....

nsurl *modelurl = [[nsbundle mainbundle] urlforresource:@"timelines" withextension:@"momd"];     __managedobjectmodel = [[nsmanagedobjectmodel alloc] initwithcontentsofurl:modelurl];     nslog(@"created managedobjectmodel url: %@", modelurl);     return __managedobjectmodel; }  /**  returns persistent store coordinator application.  if coordinator doesn't exist, created , application's store added it.  */ - (nspersistentstorecoordinator *)persistentstorecoordinator {     if (__persistentstorecoordinator != nil)     {         return __persistentstorecoordinator;     }      nsurl *storeurl = [[self applicationdocumentsdirectory] urlbyappendingpathcomponent:@"timelines.sqlite"];      nserror *error = nil;     __persistentstorecoordinator = [[nspersistentstorecoordinator alloc] initwithmanagedobjectmodel:[self managedobjectmodel]];     if (![__persistentstorecoordinator addpersistentstorewithtype:nssqlitestoretype configuration:nil url:storeurl options:nil error:&error])     {         /*          replace implementation code handle error appropriately.           abort() causes application generate crash log , terminate. should not use function in shipping application, although may useful during development.            typical reasons error here include:          * persistent store not accessible;          * schema persistent store incompatible current managed object model.          check error message determine actual problem was.            if persistent store not accessible, there typically wrong file path. often, file url pointing application's resources directory instead of writeable directory.           if encounter schema incompatibility errors during development, can reduce frequency by:          * deleting existing store:          [[nsfilemanager defaultmanager] removeitematurl:storeurl error:nil]           * performing automatic lightweight migration passing following dictionary options parameter:           [nsdictionary dictionarywithobjectsandkeys:[nsnumber numberwithbool:yes], nsmigratepersistentstoresautomaticallyoption, [nsnumber numberwithbool:yes], nsinfermappingmodelautomaticallyoption, nil];           lightweight migration work limited set of schema changes; consult "core data model versioning , data migration programming guide" details.           */         nslog(@"unresolved error %@, %@", error, [error userinfo]);         abort();     }          return __persistentstorecoordinator; }  #pragma mark - application's documents directory  /**  returns url application's documents directory.  */ - (nsurl *)applicationdocumentsdirectory {     return [[[nsfilemanager defaultmanager] urlsfordirectory:nsdocumentdirectory indomains:nsuserdomainmask] lastobject]; }      @end 

if understood have separate project utility coredata, if yes take @ question of mine. made me crazy time ago !!!

how include bundle in main project xcode 4.1


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -