I have a button in a test iPhone0 application that opens StackOverflow questions based on their GET ID in the URL. Every time the button is pressed, the page should reload to the next question.
I keep count of the GET ID through a int count initially set to 1 and incremented every button press.
Hard-coding the URL using: NSString *urlAddress=[NSString stringWithFormat:@"http://stackoverflow.com/questions/1"];
works, but obviously doesn’t allow for use of the counter. When I try to implement the counter with:
NSString *urlAddress =[NSString stringWithFormat: @"http://stackoverflow.com/questions/%@", count];
The program fails with the OBJC_MSGSEND error. Why does this line of code not work?
*I have debugged and this is the first line that causes said error.
Thanks.
countisn’t an object. You need to use%d, not%@. Using%@as a format specifier means “send adescriptionmethod to the object I’ve provided as an argument”. Since your variablecountis not in fact an object, you can’t send any messages to it.Your code (shortened to show the example better), looks like this:
Which is (pretty much) equivalent to this:
As you can imagine, the runtime can’t make heads or tails of that (
countbeing anint, after all). Using this format will work: