I stworzył UserModel.xcdatamodeld z jednego aktu: userbase i dodałem atrybut, którego nazwa jest UserID i typ jest Integer 32.XCode 4.2 NSManagedObject kontekst build udało
Po tym, tworzę dla niego zajęcia z pliku -> nowy plik-> podklasa NSManagedOBject, która automatycznie tworzy UserBase.h i .m.
W moim kontroler importowany plik UserBase.h i utworzyć właściwość:
NSManagedObjectContext *userBaseObjectContext;
z
@property (nonatomic, retain) NSManagedObjectContext *userBaseObjectContext;
w pliku mycontroller.m syntetyzowana właściwość userBaseObjectContext i funkcji DidLoad Próbowałem to :
UserBase *userObject=(UserBase *)[NSEntityDescription insertNewObjectForEntityForName:@"UserBase" inManagedObjectContext:userBaseObjectContext];
[userObject setUserID:[NSNumber numberWithInt:42]];
NSError *error;
if(![userBaseObjectContext save:&error])
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Application error" message:@"error" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil,nil];
[alert show];
[alert release];
}
else
NSLog(@"not working...");
Kiedy próbuję zbudować mój projekt, mam to e rror:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_NSEntityDescription", referenced from:
objc-class-ref in LoginController.o
"_OBJC_METACLASS_$_NSManagedObject", referenced from:
_OBJC_METACLASS_$_UserBase in UserBase.o
"_OBJC_CLASS_$_NSManagedObject", referenced from:
_OBJC_CLASS_$_UserBase in UserBase.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Co to oznacza?
Śledziłem ten tutorial: http://mobile.tutsplus.com/tutorials/iphone/iphone-core-data/
Spróbuj dodać CoreData.framework. – rjstelling
To działa. Dzięki ... – mudlee