Re: NSMutableDictionary and retirieving data from web
Re: NSMutableDictionary and retirieving data from web
- Subject: Re: NSMutableDictionary and retirieving data from web
- From: Ibrahim Bulut <email@hidden>
- Date: Tue, 13 Apr 2004 19:54:50 +0200
On Apr 13, 2004, at 09:07, Pandaa wrote:
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. ^^'
Ok, I see your point. Please enlighten me if there is a smarter way to
do this, I'm current working with my first cocoa application (besides
examples etc) and would be happy to be pushed to the right direction :)
( 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.
)
I'm aware of this, but wanted to simplify my "problem" to you guys and
make the basic thing work before implementing it the way it should be.
Ok, I'll probally go by and use NSScanner as you and Mmalc pointed out.
(( And if you have many rows - remember to cache method pointers for
every method call you need to make on a per-row basis!! ))
Can you show me small example?
Thanks :)
/Ibrahim
_______________________________________________
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.