jpswain
jpswain

Reputation: 14732

Validation not automatically called except when using KVC key-value-coding access

I implemented a KVC validation method that is called by coredata, but is not being called when I call person.name = @"alice";

is there a reason why KVC validation methods, in this case,


- (BOOL)validateName:(id *)ioValue error:(NSError **)outError {
    NSLog(@"validateName is validating...");    
    // ...    
}

is not being called when setting a value via property expression?

Another problem is that I can't get this to work either:


[person setValue:@"ok" forKey:@"name"];

My NSLog line NEVER gets called.

Anything I'm missing?

This class is a subclass of NSManagedObject.

Does that matter?

Thanks,
Jamie

Upvotes: 0

Views: 419

Answers (1)

Lily Ballard
Lily Ballard

Reputation: 185721

According to the Managed Object Validation documentation, validation methods are not run until the context is saved, or until you manually validate (with -validateForUpdate:, -validateForInsert:, or -validateForDelete:).

Upvotes: 1

Related Questions