Re: Can keypaths contain array indexes?
Re: Can keypaths contain array indexes?
- Subject: Re: Can keypaths contain array indexes?
- From: Kyle Sluder <email@hidden>
- Date: Thu, 21 Jul 2011 12:24:24 -0700
On Thu, Jul 21, 2011 at 12:08 PM, Jens Alfke <email@hidden> wrote:
> I’ve got a data model that looks sort of like this (expressed as JSON):
> [{“uuid": “abcdef”, “name": [“Fred”, “Smith”]} … ]
> I want to bind an array of these to an NSTableView, with the first and last name in different columns. So I need to create a keypath that refers to the first or second element of the array value of the “name” property.
>
> Is this possible? I’ve looked through the docs and can’t find anything about it. I’ve guessed at paths like
> name.0
> or
> name[0]
> but they throw exceptions at runtime.
Think about this for a second: this would involve creating an observer
on [someArray valueForKeyPath:@"0"]. We know that NSArray is not KVO
compliant, since its implementation of -addObserver:… is documented to
raise an exception. Therefore this can't work. :)
> (And no, I can’t change the schema to avoid having an array. It’s part of the way the data comes back from the server.)
Can you bind the entire "name" property and use a value transformer
that extracts the desired component from the array?
--Kyle Sluder
_______________________________________________
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