Jomnipotent17
Jomnipotent17

Reputation: 461

Strange BAD_EXC_ACCESS when declaring a string

Okay, all I am doing is setting an NSString to a value with this code:

NSString *stringURL = [NSString stringWithFormat:@"http://api.themoviedb.org/3/movie/%@/trailers?api_key=1523229ded5824dab8bb7840782db266",searchID];

This is a string that I then turning into a URL for querying the TMDB database. This line of code gives me a BAD_EXC_ACCESS and it is blowing my mind because using this sort of NSString construction is something I have done thousands of times without a problem.

The one other thing to note is that this line is being executed right after another query call is made. The weird thing is that call makes the stringURL the same way, yet it works fine.

Any help would be appreciated...

Upvotes: 0

Views: 367

Answers (3)

Shebuka
Shebuka

Reputation: 3228

If it's an NSInteger you need to use %ld or you will got a warning, you can also use %d and explicitly cast to int via (int)searchID

Upvotes: 0

Kapil Kumar
Kapil Kumar

Reputation: 104

You need to use the following NSString *stringURL = [NSString stringWithFormat:@"http://api.themoviedb.org/3/movie/%d/trailers?api_key=1523229ded5824dab8bb7840782db266",searchID];

Because searchID has NSInteger type and you are using "%@"

Upvotes: 0

wattson12
wattson12

Reputation: 11174

You need to use %i to log an NSInteger, not %@

Upvotes: 3

Related Questions