Bigger Better logging in Xcode
For those of you who have come from web development to iOS development, one of the things that may have disappointed or even surprised you is that the Xcode debugger is not as useful as say chrome’s, when it comes to logging.
Additionally, on that magnificent day when you submit your first app, you will sit at home waiting for the confirmation email that your app has been rejected. The fine print will tell you that you can not print any NSLog statements in your app. Then you have the fun experience of finding any of the remaining NSLog statements and deleting or commenting them out.
I would like to offer an alternative to NSLog -> BBlog. This is not some radical new discovery I am sharing, lots of people do it, I just found it helpful and thought it would make for a great new post.
#define BBLog( s, ... ) NSLog( @"%@ @ %d :: %@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )
#define BBLog( s, ... )
Its has 2 big benefits:
- It logs the file and line number of every BBLog call.
- By removing the
you will have all the logging removed without changing the code making Apple happy again.
Simply add the above code to your AppName-Prefix.pch file
Replace all your