iphone - Undeclared identifier error when adding Core Data to existing Xcode project -


i have existing project , want use coredata.

upon creation of project, coredata.framework added under frameworks group, , under link binary libraries in project's target -> build phases. didn't check "use core data" when created project--the check box not there--it in project. use xcode version 4.6.3.

reading tutorials, went app-prefix.pch , added import coredata. looks this:

#import <availability.h>  #ifndef __iphone_5_0 #warning "this project uses features available in ios sdk 5.0 , later." #endif  #ifdef __objc__     #import <uikit/uikit.h>     #import <coredata/coredata.h>     #import <foundation/foundation.h> #endif 

then, added following in appdelegate.h:

@property (readonly, nonatomic, strong) nsmanagedobjectcontext *managedobjectcontext; @property (readonly, nonatomic, strong) nsmanagedobjectmodel *managedobjectmodel; @property (readonly, nonatomic, strong) nspersistentstorecoordinator *persistentstorecoordinator;  - (void)savecontext; 

and now, when override getter managedobjectcontext, xcode throws error:

use of undeclared identifier '_managedobjectcontext'; did mean 'nsmanagedobjectcontext'?

this getter method in appdelegate.m:

- (nsmanagedobjectcontext *)managedobjectcontext {     if(_managedobjectcontext != nil)         return _managedobjectcontext;      nspersistentstorecoordinator* psc = [self persistentstorecoordinator];      if(psc != nil)     {         _managedobjectcontext = [[nsmanagedobjectcontext alloc] init];         [_managedobjectcontext setpersistentstorecoordinator:psc];     }      return _managedobjectcontext; } 

i tried putting .pch file in copy bundle resources no avail. help?

you've set correctly (note don't need add pch copy bundle resources build phase). reason you're getting error because _managedobjectcontext ivar not getting synthesized, because you're overriding getter on read-only property. either need change property readwrite (which wouldn't recommend), redefine property readwrite in class extension, or define ivar manually in class extension or implementation block.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -