Hi
I have some NSManagedObjects and I would like to write methods for sorting and comparing the properties on them.
My problem is that since Core Data defines the properties as @dynamic they can not be referenced at compile time. This means that decorating an NSManagedObject with methods like this:
- (NSComparisonResult) compareDateAndTime:(Event *) event {
return [originDate compare:[event originDate]];
}
will result in the compiler not being able to locate a property called "originDate". The above method is called like this:
NSArray *events = [[NSArray alloc]
initWithArray:[unsortedEvents sortedArrayUsingSelector:@selector(compareDateAndTime:)]];
I could go with predicates or fetchedResultController, but I would like to build these as methods myself as I have an identical NSObjects for each NSManagedObject. This NSObject acts as a temp object that is passed around and populated before it's properties are set on the NSManagedObject that is then persisted. I also have some other functions, like specialized accessors, I would like to add to the NSManagedObject.
(1)Is there a general/best practice way of decorating NSManagedObjects with methods and functions (2)and have Xcode not overwrite them when "re-building" a class for an Entity?
Thank you for any help or "RTFM" given:)