建立NSManagedObject的子類時,有一點是在這中間要強調的一點是,要不要勾選 Use scalar properties for primitive data types。數據庫
勾選上這個選項以後就是使用的是你在定義的時候使用的原始數據類型。fetch
若是沒有勾選的話,就會存在類型的轉化,轉換狀況以下:ui
以後生成四個文件以下:spa
1 //創建匹配請求,並添加判斷語句 2 NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Bowtie"]; 3 NSString *firstTitle = [self.segmentedControl titleForSegmentAtIndex:0]; 4 request.predicate = [NSPredicate predicateWithFormat:@"searchKey == %@", firstTitle]; 5 NSArray *results = [self.managedContext executeFetchRequest:request error:nil]; 6 self.currentBowtie = results.firstObject;
1 //對圖片保存進行處理 2 NSEntityDescription *entity = [NSEntityDescription entityForName:@"Bowtie" inManagedObjectContext:self.managedContext]; 3 Bowtie *bowtie = [[Bowtie alloc] initWithEntity:entity insertIntoManagedObjectContext:self.managedContext]; 4 bowtie.photoData = UIImagePNGRepresentation([UIImage imageNamed:dict[@"imageName"]]);