0

I am developing an Objective-C macOS app that uses Core Data, and I am trying to enforce constraints, specifically a rather common one, to achieve a unique title for my entity. I have tried to follow the most recommended way, setting constraints for the entity in the model. As expected, the constraints are active and I cannot save the NSManagedObjectContext, however I would like to perform the validation immediately. From the docs:

How Validation Works in Core Data

How to validate is a model decision, when to validate is a user interface or controller-level decision. For example, a value binding for a text field might have its “validates immediately” option enabled. Moreover, at various times, inconsistencies are expected to arise in managed objects and object graphs.

I have a rather simple setup: A View-Based NSOutlineView driven by a NSTreeController, and a detail view, with basically NSTextFields bound to the treeController's selection. I have checked "Validates Immediately" both for the textfields in the details view, and for the textfield in the only cell type of the NSOutlineView. However, this seems to have no effect at all and I am still free to rename my managed object without Core Data intervening. I have already tried to turn off "update values continously", both in the binding settings and in the textfield's settings but with no success. Any clarification is highly appreciated. Thanks

Alfonso Tesauro
  • 1,730
  • 13
  • 21
  • See [How to add unique constraints for some fields in Core Data](https://stackoverflow.com/questions/21130427/how-to-add-unique-constraints-for-some-fields-in-core-data). "Keep in mind conflict resolution only happens during saves, and not inserts." and "The uniqueness is checked when you do managedObjectContext.save() not while you're just adding objects to the managed object." – Willeke Oct 09 '20 at 13:24
  • Have you implemented `validateUserInterfaceItem` for the text fields? – Tom Harrington Oct 09 '20 at 17:24

0 Answers0