Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Wunk

macrumors newbie
Original poster
Nov 17, 2008
24
0
Netherlands
I'm trying to wrap my head around on how to return a comma-seperated list of items from an Array of numbers..

What I do is call a SQLite class (manages a lot of background SQLite work)

Code:
- (NSArray *)receptids {
	return [SQLiteAccess selectManyValuesWithSQL:@"select receptid from recepten order by dateadded"];
}

This query returns a list of ID's and fills them in an array like:
000001
000002
000003

Then in another class I can call the resulting array with appDelegate.receptids

Now what I want to do is grab these ID's and stick them in a NSURL in the following way:
Code:
NSURL *jsonURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.blah.com/list.php?var=ids/%@",];

At the %@ the ID's need to go in the format of 000001,000002,000003

What's the best approach to properly format the array of ID's into a comma-seperated list like that and pass it to the variable at the end of the NSURL?
 

Wunk

macrumors newbie
Original poster
Nov 17, 2008
24
0
Netherlands
Thanks, componentsJoinedByString did the trick perfectly, self.receptids calls a sqlite query from a local database:

Code:
NSURL *jsonURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.some-address.com/call.cgi?format=json&ids/%@",[self.receptids componentsJoinedByString:@","]]];

Thanks a ton, I'm filing this one under 'another great xcode command to know' :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.