Re: Enumerator and
Re: Enumerator and
- Subject: Re: Enumerator and
- From: Onar Vikingstad <email@hidden>
- Date: Tue, 9 Apr 2002 21:13:52 +0200
Thank you, Andy and Ondra!
It was actually a lot easier than what I was thinking. I got it working
by doing the changes you recommended and you were right the array
containing NSCFDictionary (not nested arrays which I had managed to
type) and I just used [tempString appendString:[tempObject
objectForKey:@"username"]]; to get the value from it.
Everything is working "swell" now though, doing just what I was looking
for. Thank you guys :)
Kind regards,
Onar Vikingstad
On tirsdag, april 9, 2002, at 06:11 , Andy Lee wrote:
At 5:40 PM +0200 4/9/02, Onar Vikingstad wrote:
I'm trying to do something that's seeminly easy: to "convert" an array
(records) into a special formatted string (I chose to use enumerator
and while function to have full control). But I keep getting run
errors when this action (doit) is executed:
[NSCFDictionary intValue]: selector not recognized
[NSCFDictionary intValue]: selector not recognized
Here's my little snippet of code:
- (IBAction)doit:(id)sender
{
NSEnumerator* enumerator = [records objectEnumerator];
NSMutableString *tempString = [NSMutableString
stringWithCapacity:4];
id tempObject,index;
while ( (index = [enumerator nextObject]) ) {
tempObject = [records objectAtIndex:[index intValue]];
[tempString appendString:[[records objectAtIndex:[index
intValue]] componentsJoinedByString:@":"]];
}
NSLog(@"Array: %@", [tempString self]);
}
You're misunderstanding what "[enumerator nextObject]" returns. It
returns an actual element from your array -- the first element the
first time you call it, the second element the second time you call it,
etc. So your code can actually be simpler:
NSEnumerator* enumerator = [records objectEnumerator];
NSMutableString *tempString = [NSMutableString
stringWithCapacity:4];
id tempObject;
while ( (tempObject = [enumerator nextObject]) ) {
[tempString appendString:[tempObject componentsJoinedByString:@":"]];
}
NSLog(@"Array: %@", tempString);
(While I was at it I simplified the final NSLog statement as well --
you can just say "tempString" instead of "[tempString self]".)
--Andy
_______________________________________________
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.
_______________________________________________
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.