0
votes

Using Core Data, is it possible to get to the TextBox containing the Core Data field?

  • (BOOL)validateForUpdate:(NSError **)error {

// 1) Loop through all properties on Entity.

// 2) Finding the error

// 3) Create error:

*error = [NSError errorWithDomain:EntityMetadataErrorDomain
                            code:NSManagedObjectValidationError
                        userInfo:@{ NSLocalizedFailureReasonErrorKey : @"ValidationError).", NSValidationObjectErrorKey : self }];

// Options

// 1) Let the Context react on the error

// or 2) use NotificationCenter and hook up a method to respond to a notification.

I am looking for the right strategy?

Thanks

1

1 Answers

2
votes

I am not a big fan of using Core Data's data validation on iOS for this type of situation. The validation portion of Core Data was originally written before iOS existed and it was much easier (expected even) to wire Core Data directly to the User Interface with Cocoa Bindings. Without Cocoa Bindings it really doesn't make sense.

My recommendation is to have the view controllers handle data validation (and subsequent user errors) and use Core Data validation as a second line of defense at most.

I rarely use Core Data validation on iOS beyond simple not-null checking.