【发布时间】:2023-03-30 06:16:02
【问题描述】:
在尝试设置值之前,我需要检查是否存在 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];
}
【问题讨论】:
标签: objective-c core-data ios5 nsentitydescription