• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Extending KVO to scalar struct types?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Extending KVO to scalar struct types?


  • Subject: Extending KVO to scalar struct types?
  • From: Graham Cox <email@hidden>
  • Date: Fri, 29 Aug 2014 13:25:56 +1000

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 (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


  • Follow-Ups:
    • Re: Extending KVO to scalar struct types?
      • From: Ken Thomases <email@hidden>
    • Re: Extending KVO to scalar struct types?
      • From: Jens Alfke <email@hidden>
  • Prev by Date: Re: NSScrollView with Custom View Not Working...
  • Next by Date: Re: Extending KVO to scalar struct types?
  • Previous by thread: Re: NSScrollView with Custom View Not Working...
  • Next by thread: Re: Extending KVO to scalar struct types?
  • Index(es):
    • Date
    • Thread