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: Quincey Morris <email@hidden>
- Date: Tue, 13 Jun 2017 23:41:12 -0700
On Jun 13, 2017, at 23:32 , Glen Huang <email@hidden> wrote:
>
> n 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 don’t “do” Core Data any more (I can’t afford the therapy afterwards), but I
get the impression from the documentation that one way is to do
“cross-property” validation in some parent property.
Alternatively, put a required location property on Child2, and a *transient*
location property on the parent that retrieves the child property as
appropriate. (Indeed, you can put plain properties on your parent entity class,
and stay out of the CD model for this extra property.)
> 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.
I dunno. (See above under therapy.) Be careful with Swift 4, because methods
might not be inferred to be @objc any more. You might need to do something
explicit to get this method into the Obj-C runtime. Core Data is,
unfortunately, deeply stuck in the Obj-C world.
_______________________________________________
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