Thanks for quick reply.

I guess i should provide the full context, sorry I was unclear.

In my case, the location attribute is actually defined on a parent entity 
(let's call it Parent), and it has two child entity (Child1 and Child2), I want 
location to be optional for Child1 but not for Child2. So I made location to be 
optional on Parent, and defined a validation rule on Child2 to prevent nils.

Is that something possible to do in Core Data?

I had an epiphany when you mentioned it's validated only if non-nil. So the 
validation only works when the attribute isn't nii? But I tried to add this

    func validateName(_ value: AutoreleasingUnsafeMutablePointer<AnyObject?>) 
throws {
        print(value.pointee)
    }

And only "succeed" was printed. So it seems the validation didn't run for name 
either.


> On 14 Jun 2017, at 10:36 AM, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Jun 13, 2017, at 19:10 , Glen Huang <hey...@gmail.com 
> <mailto:hey...@gmail.com>> wrote:
>> 
>> 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
> 
> I don’t understand this. If you made the “location” attribute optional, I 
> would expect it to be validated only if non-nil. If the location is never 
> set, it’s nil by default, so why are you expecting validation to occur?
> 

_______________________________________________

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