Cocoa – Formatting URL parameters in an NSURL object

cocoansurl

I want to pass parameters in an NSURL. For example, I have

NSURL *url = [NSURL URLWithString:@"http://demo.digi-corp.com:82/Nilesh/betBuddy/api/getEventsXML.php?sp_ID=2"]; 

where sp_ID can be 1, 2, 3, 4, etc.
How can i do it? Please help me out.

Best Answer

You can use the method [NSString stringWithFormat:@""] to format your URL string. For example,

NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"http://e.com/?var=%d", 2]];

If you look in the documentation for string format specifiers you can find out exactly what characters to use for each type of replacement (integer, double, object, etc).

Related Topic