On May 02, 2016, at 01:49 PM, "ftes...@bluewin.ch" <ftes...@bluewin.ch> wrote:

Le 2 mai 2016 à 18:59, Alex Zavatone <z...@mac.com> a écrit :
…
I had no idea that using KVC that something as arbitrary as this was even possible - let alone if it is a good idea.
For it being a good idea, it's obscure as can be, so no. But does KVC allow you 
to be as arbitrary as that with *any* object (in this case, an NSDictionary) to 
another that originates from an NSObject with NSCoding protocols?
***
I don’t know if it’s a good idea, but it’s not available for all classes. It’s 
an extension of CALayer and CAAnimation :
<https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreAnimation_guide/Key-ValueCodingExtensions/Key-ValueCodingExtensions.html>

There's also this in <objc/runtime.h>. We used it a lot at a previous job. So 
much so that someone added a category to NSObject so we could easily add and get 
named objects on any object.

/** * Sets an associated value for a given object using a given key and association policy. * * @param object The source object for the association.
* @param key The key for the association.
* @param value The value to associate with the key key for object. Pass nil to 
clear an existing association.
* @param policy The policy for the association. For possible values, see 
“Associative Object Behaviors.”
* * @see objc_setAssociatedObject
* @see objc_removeAssociatedObjects
*/
OBJC_EXPORT void objc_setAssociatedObject(id object, const void *key, id value, 
objc_AssociationPolicy policy)
__OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_1);

/** * Returns the value associated with a given object for a given key. * * @param object The source object for the association.
* @param key The key for the association.
* * @return The value associated with the key \e key for \e object. * * @see objc_setAssociatedObject
*/
OBJC_EXPORT id objc_getAssociatedObject(id object, const void *key)
__OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_1);

/** * Removes all associations for a given object. * * @param object An object that maintains associated objects. * * @note The main purpose of this function is to make it easy to return an object * to a "pristine state”. You should not use this function for general removal of
* associations from objects, since it also removes associations that other 
clients
* may have added to the object. Typically you should use \c objc_setAssociatedObject * with a nil value to clear an association. * * @see objc_setAssociatedObject
* @see objc_getAssociatedObject
*/
OBJC_EXPORT void objc_removeAssociatedObjects(id object)
__OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_1);

Sent from iCloud's ridiculous UI, so, sorry about the formatting

 
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (Xcode-users@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/xcode-users/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to