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
Post a Comment