objective-ccore-dataxcdatamodelnsentitydescriptionfetched-property

CoreData Entity Fetch Request


I have an entity called TimeInterval whose only attributes are a startDate and finishDate, their type is Date. I obviously do not need to add another attribute called totalTime because that can be calculated by doing: [finishDate timeIntervalSinceDate: startDate]

Can I create a fetched property for the attribute totalTime? If not then what is the best way to go about this without having to add totalTime as an attribute as that seems redundant.

I am new to Core-Data by the way.


Solution

  • It seems using fetched properties would not work for my situation. A simple category on TimeInterval does the trick:

    @implementation TimeInterval (Extras)
    
    -(NSTimeInterval)intervalTime
    {
        return [self.finisheDateTime timeIntervalSinceDate: self.startDateTime];
    }
    
    @end