I need a way to handle dynamic properties in an NSManagedObject subclass. What I do now is to check if an object’s date (NSDate class) property is passed by [NSDate now]. If that date is property is passed then the object is flagged as overdue.
So whenever I need to show if an object is overdue I need to do the comparison above. So this property can switch states being overdue and not being overdue. It seems kind of wrong to do this check all the time. Is there some way to do this automagically? I. e. every time I fetch the objects from the database Core Data will perform this above method for me?
You can achieve what you are looking for by using NSManagedObject subclasses, and transient attributes.
The dynamic property that you want can be achieved by making a ‘transient’ attribute. You can make an attribute transient by checking the transient option. Transient attributes are not persisted to the local store.
Create a NSManagedObject subclass for your entity by using the New File wizard, it’s located under the category ‘Core Data’.
When the class is created, just create a getter method for your dynamic property to return what you want.
Now you can use this as normal during your fetch requests.