Make Custom Struct Key-Value Coding Compliant
Make Custom Struct Key-Value Coding Compliant
- Subject: Make Custom Struct Key-Value Coding Compliant
- From: Richard Somers <email@hidden>
- Date: Sat, 11 Feb 2012 23:43:57 -0700
Core Data Question
I have a custom struct that I would like to make key-value coding compliant so it will work with Core Data as a non-standard persistent attribute. Is it possible to make a custom struct key-value coding compliant?
I would rather not store it in the managed object as an object but would like to leave it as a struct and have it work just like NSPoint, NSSize, NSRect, or NSRange.
Core Data Programming Guide
Non-Standard Persistent Attributes
Scalar Value Constraints
"A requirement of the accessor methods you write is that they must be key-value coding (and key-value observing) compliant. Key-value coding only supports a limited number of structures—NSPoint, NSSize, NSRect, and NSRange."
"If you want to use a scalar type or structure that is not one of those supported directly by Core Data and not one of the structures supported by key-value coding, you must store it in your managed object as an object-typically an NSValue instance, although you can also define your own custom class. You will then treat it as an object value as described later in this article. It is up to users of the object to extract the required structure from the NSValue (or custom) object when retrieving the value, and to transform a structure into an NSValue (or custom) object when setting the value."
--Richard
_______________________________________________
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