Hi there, I'm Marcos!


Extending CoreData entities

In Swift, core data entities can be extended to provide them with additional functionality. Imagine that you’ve got an entity called Task with two fields: creationDate and completionDate. You could extend the entity to compute the amount it took to complete the task:

extension Task {
    func timeSpent() {
        return self.completionDate.timeIntervalSince(self.creationDate)