ahoura ahoura - 2 months ago 19
Objective-C Question

NSLog doesnt work with float?

I am trying to do nslog on a float value using :

NSLog(@"THE LOG SCORE : %@", x);


and I have also tried :

NSLog(@"THE LOG SCORE : %@", [NSString stringWithFormat:@"%@", x]);


but it doesnt work! any thoughts why it wouldnt work? the error I get is
EXC_BAD_ACCESS


thanks

Answer

The %@ is intended to work on an object, a float is not an object. To do a float try:

NSLog(@"THE LOG SCORE : %f", x);

Here's a helpful article

http://vormplus.be/blog/article/using-nslog-to-debug-your-iphone-application