Re: NSMutableDictionary and retirieving data from web
Re: NSMutableDictionary and retirieving data from web
- Subject: Re: NSMutableDictionary and retirieving data from web
- From: Pandaa <email@hidden>
- Date: Tue, 13 Apr 2004 09:35:34 +0200
Hi all,
I have a problems with filling my tableview with data from my
NSMutableDictionary object. The problem is I get hold of the data
from
an url wich is tab seperated data stream. Is there any way to fill a
NSDictionary object with this data and give the key names to the data
fields?
If I understand what you want, something like this should work:
NSArray *keyArray = [[NSArray alloc] initWithObjects:@"programStart",
@"programEnd", @"programChannel", @"programTitle",
@"programDescription", @"programAlarm", nil];
NSString *data2 = [[NSString alloc] initWithContentsOfURL:[[NSURL
alloc] initWithString:theUrl]];
NSArray *myArray = [[NSArray alloc] initWithArray:[data2
componentsSeparatedByString:@"\t"];
NSDictionary *rowData = [[NSDictionary alloc] initWithObjects:myArray
forKeys:keyArray];
[channelData addObject:rowData];
Does that look about right?
Hi again :)
Your example works for only for a single "row" at a time, so made a
loop and grabbed one "line" of my data at time and added it to the
tableview datasource.
Now it works perfectly.
Thanks for the help!
Now, of course, for performance, you would never do something like
[[NSArray alloc] initWithArray:[data2
componentsSeparatedByString:@"\t"], but that's really beside the point,
sorry. ^^'
( Not to mention that if part of your data isn't textual, but rather a
textual representation of numerical values, you would want to use
NSScanner so you can avoid creating lots of temporary string objects. )
(( And if you have many rows - remember to cache method pointers for
every method call you need to make on a per-row basis!! ))
. . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . .
. . . . earth water fire air software - the five elements . . . .
. . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . .
. email@hidden . . www.synapticpulse.net .
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.