objective c - when adding a relationship object w/ core data get "property cannot be found in forward class object" error -
i have core data model 4 entities. entity player
has to-many relationship other entities (player_scores,custom_exercise,selected_exercise
).
in app delegate, make nsmanagedobjectcontext,nsmanagedobjectmodel,nspersistentstorecoordinator
properties in standard way. then, in different view controller, declare ivars nsmanagedobjectcontext
object , newplayer
player entity in @interface:
@interface newprofileviewcontroller() { nsmanagedobjectcontext *context; player *newplayer; }
then in action have following code create player entity , enter in attributes, player_scores
entity , selected_exercise
entity. code use adds attributes player_scores
, player entities. when try add 16 selected_exercise
entities in loop , set attributes big fat "property cannot found on forward class object?" error. help!!!!! said code same selected_exercise
, player_scores
. tried re-starting, deleting database, etc. it's compiler error pops when try newex.exercise=@"blahblahblah";
or newex.suit=@"blahblahblah";
ugh
below code method:
//1. save person database newplayer=[nsentitydescription insertnewobjectforentityforname:@"player" inmanagedobjectcontext:context]; newplayer.name=newentry; //nserror *error; [context save:&error]; //2. begin making score card: player_scores *newscorecard = [nsentitydescription insertnewobjectforentityforname:@"player_scores" inmanagedobjectcontext:context]; newscorecard.date_of_game = [nsdate date]; newscorecard.player=newplayer; //attach score card new playe [newplayer addscoresobject:newscorecard];//add score card newplayer //3. make selected_exercise nsstring *plistcatpath = [[nsbundle mainbundle] pathforresource:@"listofexercises" oftype:@"plist"]; //grab plist nsmutablearray* thedictarray= [[nsmutablearray arraywithcontentsoffile:plistcatpath] copy]; for(int cnt=0;cnt<[thedictarray count];cnt++){ selected_exercise *newex= [nsentitydescription insertnewobjectforentityforname:@"selected_exercise" inmanagedobjectcontext:context]; newex.exercise=[[thedictarray objectatindex:cnt]valueforkey:@"exercise"]; newex.suit=[[thedictarray objectatindex:cnt]valueforkey:@"suit"]; [newplayer addselected_exerciseobject:newex]; nslog(@"added exercise %@ suit %@ @ array index %d",[[thedictarray objectatindex:cnt]valueforkey:@"exercise"],[[thedictarray objectatindex:cnt]valueforkey:@"suit"],cnt); } // save nserror *error = nil; if ([context save:&error]) { nslog(@"the save successful!"); } else { nslog(@"the save wasn't successful: %@", [error userinfo]); }
that sounds if imported "player.h", not "selected_exercise.h" in file.
"player.h" contains forward declaration @class selected_exercise
, compiler not complain on
selected_exercise *newex = [nsentitydescription ...
but if "selected_exercise.h" not imported, properties of class, such newex.exercise
, unknown compiler.
Comments
Post a Comment