D
D
Dmitry2015-12-18 15:00:39
Objective-C
Dmitry, 2015-12-18 15:00:39

How to assign a value to an object property in the willsave method of the NSManagedObject class?

- (void)willSave {
    self.flag = true;
}

I execute this code and I get an infinite call to the willSave method. How to avoid it?
-(void)willSave {
    NSDate *now = [NSDate date];
    if (self.modificationDate == nil || [now timeIntervalSinceDate:self.modificationDate] > 1.0) {
        self.modificationDate = now;
    }
}

Found this code on stackoverflow, but if I understand correctly, save will be called twice. Could this negatively impact performance?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question