Question

I need to insert string parameters startDate and endDate into URL string and I am trying with stringWithFormat, however xcode complains about many other characters in the URL string which it interprets probably as invalid specifiers.

NSString *urlString = [NSString stringWithFormat:@"https://api.xmltime.com/astronomy?accesskey=l1fMY6Om37&expires=2013-06-05T18%3A00%3A00%2B00%3A00&signature=12P2tr1MyD4NnLjqhWzc%2BpsBKR0%3D&object=sun&placeid=netherlands%2Famsterdam&startdt=2013-06-04&enddt=2013-07-04&geo=0&isotime=0&lang=en&utctime=0&types=all", startDate, endDate];

I put my variables with %@ specifiers on the place of 2013-06-04 and 2013-07-04 strings. I guess xcode does not like the other percent signs in the string. What is the right way of setting parameters in this string? Thank you.

Was it helpful?

Solution

Use %% to place % in stringWithFormat.

So your code becomes:

NSString *urlString = [NSString stringWithFormat:@"https://api.xmltime.com/astronomy?accesskey=l1fMY6Om37&expires=2013-06-05T18%%3A00%%3A00%%2B00%%3A00&signature=12P2tr1MyD4NnLjqhWzc%%2BpsBKR0%%3D&object=sun&placeid=netherlands%%2Famsterdam&startdt=2013-06-04&enddt=2013-07-04&geo=0&isotime=0&lang=en&utctime=0&types=all", startDate, endDate];

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top