I'm working with a core data entity that has four date attributes - syncDate, historicSyncDate, etc.
Is there a way I can write a single method that would take a NSString name of one of these attributes and assign a proper date for it?
Ex:
-(void)updateDate:(NSDate*) date forAttribute:(NSString*)attribute forService:(Service*)service
{
//based on attribute name, set service.syncDate or service.historicSyncDate, etc
}
Sure:
[service setValue:date forKey:attribute];
From the "NSManagedObject Class Reference":
setValue:forKey:
Sets the specified property of the receiver to the specified value....
If key identifies a to-one relationship, relates the object specified by value to the receiver, unrelating the previously related object if there was one. Given a collection object and a key that identifies a to-many relationship, relates the objects contained in the collection to the receiver, unrelating previously related objects if there were any.This method is overridden by NSManagedObject to access the managed object’s generic dictionary storage unless the receiver’s class explicitly provides key-value coding compliant accessor methods for key.