Re: easy way to store table-like data

2011-03-08 Thread Matt Neuburg
On Mon, 07 Mar 2011 12:29:27 -0800, Dave DeLong  said:
>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"];
>
>On Mar 7, 2011, at 12:26 PM, Martin Batholdy wrote:
>
>> 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)?

I am surprised that no one has mentioned blocks. For example, if you restrict 
yourself to Mac OS X 10.6 or later, or iOS 4 or later, you can call 
keysOfEntriesPassingTest:, and similarly for arrays. Your best bet is to look 
over the documentation (e.g., if you want to know what you can do with an 
NSDictionary, read the class reference for NSDictionary; if you want to know 
what you can do with an NSArray, read up on NSArray; etc.).

However, I'd also point out that you may be combining two or three different 
issues in the way your original question is posed. How your data are stored is 
one thing (could be sqlite; on the other extreme, could be simple tab-delimited 
text). How they are manipulated is another (could be NSDictionary, NSArray, 
etc., or, as Dave DeLong rightly suggests, a class devoted to data structured a 
particular way). How they are presented in the interface is yet another. m.

--
matt neuburg, phd = m...@tidbits.com, 
A fool + a tool + an autorelease pool = cool!
Programming iOS 4!
http://www.apeth.net/matt/default.html#iosbook___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: easy way to store table-like data

2011-03-07 Thread Wim Lewis

On 7 Mar 2011, at 12:26 PM, Martin Batholdy wrote:
> Is it also possible to filter the entries of an NSDictionary like in SQL?

Yes (as Dave DeLong describes). If you just need to filter it for display and 
are using NSArrayController you can also use -setFilterPredicate:. It's 
presumably doing the same thing under the hood.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: easy way to store table-like data

2011-03-07 Thread Dave DeLong
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 (Cocoa-dev@lists.apple.com)
>> 
>> 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:
>> http://lists.apple.com/mailman/options/cocoa-dev/batholdy%40googlemail.com
>> 
>> This email sent to batho...@googlemail.com
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/davedelong%40me.com
> 
> This email sent to davedel...@me.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: easy way to store table-like data

2011-03-07 Thread Martin Batholdy
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 (Cocoa-dev@lists.apple.com)
> 
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/batholdy%40googlemail.com
> 
> This email sent to batho...@googlemail.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: easy way to store table-like data

2011-03-07 Thread Wim Lewis
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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com