【发布时间】:2011-12-02 16:28:03
【问题描述】:
我创建了一个带有一个条目的 UserModel.xcdatamodeld:UserBase,并添加了一个名称为 UserID 且类型为 Integer 32 的属性。
之后,我使用 file->new file->NSManagedOBject 子类为其创建类,它会自动创建 UserBase.h 和 .m。
在我的控制器中导入 UserBase.h 文件,并创建一个属性:
NSManagedObjectContext *userBaseObjectContext;
与
@property (nonatomic, retain) NSManagedObjectContext *userBaseObjectContext;
在 mycontroller.m 文件中合成了 userBaseObjectContext 属性,在 DidLoad 函数中我尝试了这个:
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...");
当我尝试构建我的项目时,我收到了这个错误:
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)
这是什么意思?
我遵循了这个教程:http://mobile.tutsplus.com/tutorials/iphone/iphone-core-data/
【问题讨论】:
-
尝试添加 CoreData.framework。
标签: xcode ios5 nsmanagedobjectcontext