Re: easy way to store table-like data
Re: easy way to store table-like data
- Subject: Re: easy way to store table-like data
- From: Dave DeLong <email@hidden>
- Date: Mon, 07 Mar 2011 12:29:27 -0800
If you have an array of dictionaries, you can use -filteredArrayUsingPredicate, and pass in the NSPredicate with the format string of @"type = 'website'". You'll get back all the dictionaries where [[dictionary objectForKey:@"type"] isEqual:@"website"];
But if you're using these dictionaries for anything more than just transient referencing (ie, they're quickly create and destroyed), then I would probably recommend making a class to hold the relevant information instead of using a dictionary.
Dave
On Mar 7, 2011, at 12:26 PM, Martin Batholdy wrote:
> Hi,
>
> thanks for the reply.
>
> Is it also possible to filter the entries of an NSDictionary like in SQL?
>
> for example I have a key "type" and different entries.
>
> Is it possible to get an Array of all elements where "type" is equal to "website" (or something like that)?
>
>
>
> On 07.03.2011, at 21:05, Wim Lewis wrote:
>
>> Well, sqlite3 is available on the system (and is used by a lot of Apple code, so hopefully it won't be removed in the near future); you could simply use that, if that API is what you're most familiar with.
>>
>> However, unless you have a pretty large data set, sqlite is probably overkill and it'd be easier to use a plist. I would start with an NSArray of NSDictionaries, and then if it makes the code cleaner replace the NSDictionaries with custom objects containing the fields you're interested in and whatever other methods logically belong there.
>>
>> NSArrayController can do sorting and filtering of these objects for you for presentation in the table view; if NSArrayController doesn't do what you need then it's easy enough to sort and filter them yourself and then implement the NSTableView data source methods. Take a look at the NSArrayController and bindings API documentation--- if bindings do what you need, they're really quick and convenient.
>>
>>
>> _______________________________________________
>>
>> 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
>
> _______________________________________________
>
> 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
_______________________________________________
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