下面是我的省電方法CoreData不保存屬性作爲字符串
-(void)createData
{
// // get date and time and store in two separate variables
NSDate *today = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd/MM/yyyy"];
NSString *dateString = [dateFormat stringFromDate:today];
NSLog(@"Date is: %@",dateString);
NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
timeFormatter.dateFormat = @"HH:mm";
NSString *timeString = [timeFormatter stringFromDate:today];
NSLog(@"Time is: %@",timeString);
//
//
ReminderInfo *reminderInfo = [NSEntityDescription insertNewObjectForEntityForName:@"ReminderInfo" inManagedObjectContext:[DataManager sharedDataManager].managedObjectContext];
reminderInfo.date = today;
reminderInfo.reminderTime = @"06:30";
reminderInfo.medicationType = @"Cream";
[[DataManager sharedDataManager] saveReminderInfo:reminderInfo];
NSLog(@"reminder created");
}
下面是從控制檯輸出:
<ReminderInfo: 0x6080002887a0> (entity: ReminderInfo; id: 0xd000000000480002 <x-coredata://8055FB8D-6E6A-44B2-9456-3E6932ACBE32/ReminderInfo/p18> ; data: {
date = "2017-06-03 08:03:40 +0000";
medicationType = Cream;
reminderTime = "06:30";
})
medicationType是String
類型的屬性。正如你可以從控制檯看到的,在Cream
中沒有任何""
。這可能是沒有保存任何東西到Coredata的原因嗎?
不,不能 –