I have some NSManagedObject classes created for use with CoreData I need to add some additional properties for formatting I am doing using GRMustache templates.
Here is an example property:
-(NSString *) PriceFormatted {
NSNumberFormatter *nfm = [[[NSNumberFormatter alloc] init] autorelease];
[nfm setNumberStyle:NSNumberFormatterCurrencyStyle];
[nfm setCurrencyCode:[Helpers GetCurrencyCode]];
[nfm setNegativeFormat:@"-¤#,##0.00"];
[nfm setMaximumFractionDigits:2];
return [nfm stringFromNumber:self.Price];
}
I currently have this in my generated NSManagedObject class but this will cause issues if I need to regenerate a new NSManagedObject class.
Can I define these properties in a secondary set of classes – similar to partials in C#?
Probably the easiest way is to add a category to your generated managed object.
Here is Apple’s documentation on it, it is pretty easy.
To quote: