1.创建工程,勾选use coredata

2.添加表以及属性
在工程文件列表中选中:工程名.xcdatamodeld文件

注意:uiimage用binary data类型
3.添加Model



4.插入数据
需要用app delegate执行任务
appdelegate = [UIApplication sharedApplication].delegate;
Model *model = [NSEntityDescription insertNewObjectForEntityForName:@"Model" inManagedObjectContext:appdelegate.managedObjectContext];
model.name = _strtf.text;
model.age = [NSNumber numberWithInteger:_numtf.text.integerValue];
model.img = UIImagePNGRepresentation(_imgV.image);
[appdelegate.managedObjectContext save:nil];
网友评论