ios - Adding Core Data to existing iPhone project -


i'd add core data existing iphone project, still lot of compile errors:

- nsmanagedobjectcontext undeclared   - expected specifier-qualifier-list before 'nsmanagedobjectmodel'   - ... 

i added core data framework target (right click on project under "targets", "add" - "existing frameworks", "coredata.framework").

my header-file:

nsmanagedobjectmodel *managedobjectmodel; nsmanagedobjectcontext *managedobjectcontext;        nspersistentstorecoordinator *persistentstorecoordinator;  [...]  @property (nonatomic, retain, readonly) nsmanagedobjectmodel *managedobjectmodel; @property (nonatomic, retain, readonly) nsmanagedobjectcontext *managedobjectcontext; @property (nonatomic, retain, readonly) nspersistentstorecoordinator *persistentstorecoordinator; 

what missing? starting new project not option...

thanks lot!

edit sorry, have implementations... seems library missing... implementation methods full compile error "managedobjectcontext undeclared", "nspersistentstorecoordinator undeclared", "expected ')' before nsmanagedobjectcontext" (although seems parenthesis correct)...

#pragma mark - #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 merging of models found in      application bundle.  */ - (nsmanagedobjectmodel *)managedobjectmodel {      if (managedobjectmodel != nil) {         return managedobjectmodel;     }     managedobjectmodel = [[nsmanagedobjectmodel mergedmodelfrombundles:nil] retain];         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 = [nsurl fileurlwithpath: [[self applicationdocumentsdirectory]          stringbyappendingpathcomponent: @"core_data.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. if not possible recover error, display alert panel      instructs user quit application pressing home button.       typical reasons error here include:      * persistent store not accessible      * schema persistent store incompatible current managed object                  model      check error message determine actual problem was.      */     nslog(@"unresolved error %@, %@", error, [error userinfo]);     abort(); }      return persistentstorecoordinator; } 

all coredata header files imported in app_prefix.pch, coredata classes available throughout project, don't have manually import header in files need them.

so open xcode , file app_prefix.pch, default it's in other sources group. after uikit import statement, add following line:

#import <coredata/coredata.h> 

and should ready go.

xcode 4

for projects created in xcode 4, prefix file can found in supporting files group in project navigator. it's called 'projectname-prefix.pch' default.

xcode 6+

starting xcode 6, precompiled header file no longer included default. because of introduction of modules, take away need use precompiled headers. while still possible manually add pch file globally include coredata headers, consider specifying coredata dependency using @import coredata;* in every file uses coredata. makes dependencies explicit , more importantly avoid question's problem in future.

* modules need enabled work.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -