Hi,

I'm trying to validate an attribute of a NSManagedObject, I create a 
transformable attribute called location, make it CLLocation, and define a 
method on the object:

   func validateLocation(_ value: 
AutoreleasingUnsafeMutablePointer<AnyObject?>) throws {
       if value.pointee == nil {
           fatalError("Location can't be nil")
       }
   }

Which is adapted from the official document. In the Core Data Xcode editor, I 
enabled optional for this attribute, but I expect this method will prevent the 
object from being saved when the it's location isn't set and the context is 
saved.

But when I do that, the method isn't even called. I can confirm by setting a 
break point in the method, and it never blocks.

Apart from the previous method, I add the following to func application(_:, 
didFinishLaunchingWithOptions launchOptions:)

       let context = persistentContainer.viewContext
       let foo = Foo(context: context)
       foo.name = "foo"
       // The following should fail, since we didn't provide location value
       try! context.save()
       print("succeed")

Where Foo has a name attribute of type string and the location attribute as I 
mentioned. In my case "succeed" prints in the console.

Did I do something wrong or is it a bug on the Core Data side?  

I'm using Xcode 9 beta on macOS 10.12.5, with Swift 4 and the new building 
system.

Thanks
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to