Re: Accessing NSArray objects with a key path
Re: Accessing NSArray objects with a key path
- Subject: Re: Accessing NSArray objects with a key path
- From: Todd Blanchard <email@hidden>
- Date: Thu, 31 Mar 2005 21:11:18 -0800
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I implemented the arrangedObjects.key1.3 syntax in my java KVC library
- - pretty handy. Should be pretty easy to replace valueForKey: on
NSArray with a category to get it to do what you want. I don't think
overriding anything on NSArray is a good idea as its a class cluster I
think.
If you just want an object at the ends, you can use
arrangedObjects.key1.lastObject or firstObject.
On Mar 31, 2005, at 7:38 AM, Mike Ferris wrote:
My problem is that I want @"arrangedObjects.key1" to return an
NSArray and
I want the table column to display only, say, the first object.
Something
to the effect of @"arrangedObjects.key1.objectAtIndex:0" or just
@"arrangedObjects.key1.0".
Is this kind of operation possible? Is there some array operator like
@max or @count that I am missing? I could write a custom formatter
for
the column to pick off the part of the array I need but it seems like
there should be an easier way with the key paths. I have looked all
over
the documentation and old list threads but can't find any answers.
I've often wished for keyPath syntax that handled array indexing.
Your @"arrangedObjects.key1.0" would be the easiest to implement. All
you would need to do is override valueForKey:/setValue:forKey: on
NSArray to look for numeric keys and return objectAtIndex:.
A more satisfying (although trickier to implement yourself) syntax
would be @"arrangedObjects.key1[0]". For this you'd pretty much need
to replace the keypath methods...
Mike Ferris
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)
iD8DBQFCTNf2hullemWJdQ8RAkEuAJ9p7G1UwuWmo0DpaYadfymlgxEKogCeJfaw
RUqFHVylqTIl93pQZInIQQg=
=4QGj
-----END PGP SIGNATURE-----
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden