Re: How to validate Core Data attributes ? (example in official doc doesn't work)
Re: How to validate Core Data attributes ? (example in official doc doesn't work)
- Subject: Re: How to validate Core Data attributes ? (example in official doc doesn't work)
- From: Glen Huang <email@hidden>
- Date: Wed, 14 Jun 2017 14:32:13 +0800
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
> <email@hidden> wrote:
>
> On Jun 13, 2017, at 19:10 , Glen Huang <email@hidden
> <mailto:email@hidden>> 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 (email@hidden)
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:
This email sent to email@hidden