NSEntityDescription
在尝试设置值之前,我需要检查是否存在密钥。我有一个 JSON 数据字典,不想尝试设置对象中不存在的键。
Appointment *appointmentObject = [NSEntityDescription insertNewObjectForEntityForName:@"Appointments" inManagedObjectContext:[[DataManager sharedInstance] managedObjectContext]];
for (id key in dict) {
// Check if the key exists here before setting the value so we don't error out.
[appointmentObject setValue:[dict objectForKey:key] forKey:key];
}