1.創(chuàng)建工程局待,勾選use coredata
創(chuàng)建工程-CoreData
2.添加表以及屬性
在工程文件列表中選中:工程名.xcdatamodeld文件
創(chuàng)建表名及屬性
注意:uiimage用binary data類型
3.添加Model
coredata
勾選工程
完成后多四個文件
4.插入數(shù)據(jù)
需要用app delegate執(zhí)行任務
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];