Hi all,

I had an idea that could simplify quite a bit of tedious glue code, but I'm not 
sure if it's feasible.

-[NSObject setValue: forKeyPath:] can take a key path for any property, but not 
for fields of that property if it's a scalar struct type, e.g. 
@"myObject.location.x" isn't allowed if the 'location' property is NSPoint for 
example, because NSPoint isn't an object.

I was wondering if I could figure out a way to make this work as a 
pre-processing step prior to setting the value. So for example, knowing that I 
want to set a field of a struct property, I could call a special method that 
strips off the last part of the key path, uses the remainder to get the current 
scalar value, and then use the last part of the path to mutate the relevant 
struct field prior to setting it back, again just using the remainder of the 
keyPath.

The problem here is being able to get to the struct's field at runtime given 
its name as a string. Is that even possible? If it is my scheme should work, 
otherwise it's back to the drawing board.

Incidentally am I right in thinking that bindings is able to do this?

--Graham



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Reply via email to