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:54:16 +0800
You're the hero man!
I totally forgot about the @objc case in swift 4. After prefixing it to my
validation method, it works!
And if you don't mind me asking, what do you use instead of Core Data? It's
indeed not that friendly to swift (relationships being NSSet instead of
Set<Type> etc). Also I don't quite get the "can’t afford the therapy
afterwards" part, care to explain? (Sorry if that's a joke and I didn't get it)
Thanks.
> On 14 Jun 2017, at 2:41 PM, Quincey Morris
> <email@hidden> wrote:
>
> On Jun 13, 2017, at 23:32 , Glen Huang <email@hidden
> <mailto: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