我有一个CoreData实体,(myEntity),它有10个属性。有没有办法在数组中获取10个属性并使用所述数组设置属性值?
例如:
//To get the property:
NSArray *arrayOfProperties = <Some command>;
...
//and then to set the property value,instead of:
myEntity.property1 = <value>;
//set the property like so:
[[arrayOfProperties objectAtIndex:1] <some command to set the value>];
答案 0 :(得分:0)
如下所示:
// Create the entity in the managed object context:
MyEntity *myEntity = (MyEntity *)[NSEntityDescription insertNewObjectForEntityForName:@"MyEntity" inManagedObjectContext:[self managedObjectContext]];
// Set the properties of the entity:
entity.property1 = arrayOfProperties[0];
entity.property2 = arrayOfProperties[1];
entity.property3 = arrayOfProperties[2];
// etc...