Re: NSPredicate with non-string keys
Re: NSPredicate with non-string keys
- Subject: Re: NSPredicate with non-string keys
- From: Clark Cox <email@hidden>
- Date: Mon, 23 Mar 2009 16:50:30 -0700
On Mon, Mar 23, 2009 at 2:53 PM, Ben Einstein <email@hidden> wrote:
> I'm filtering an array of dictionaries, my usual procedure for doing this
> is:
>
> NSPredicate *predicate = [NSPredicate predicateWithFormat:@"MyKey
> CONTAINS[cd] %@", searchString];
> NSArray *filteredArray = [[self dataArray]
> filteredArrayUsingPredicate:predicate];
>
> So your comment about lowercase keys is only true for KVC compliance
> (filtering non-plist objects),
NSPredicate *uses* KVC to fetch the values to test. So, the
keys/keypaths you use therewith should be valid KVC keys. Therefore,
the "Keys must use ASCII encoding, begin with a lowercase letter, and
may not contain whitespace." holds here as well.
> not when filtering arrays of dictionaries,
> where numbers ARE valid keys. But NSPredicate doesn't seem to think so.
Numbers are never valid KVC keys.
> On Mar 23, 2009, at 5:48 PM, Kyle Sluder wrote:
>
>> On Mon, Mar 23, 2009 at 5:18 PM, Ben Einstein <email@hidden> wrote:
>>>
>>> So is there any way to filter with numberic keys? I guess I could convert
>>> all they keys to strings? Urgh....
>>
>> First, arrays don't have keys. I'm assuming you mean you need to
>> filter the items based on values for keypaths off those objects.
>>
>> And no, numbers are not valid keys. Keys must begin with a lowercase
>> letter:
>> http://developer.apple.com/documentation/Cocoa/Conceptual/KeyValueCoding/Concepts/BasicPrinciples.html#//apple_ref/doc/uid/20002170-183455
>>
>> --Kyle Sluder
--
Clark S. Cox III
email@hidden
_______________________________________________
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