Ever wanted to use NSLog in the iPhone SDK to see the value of a BOOL? Heck I have! “How do you do it”, you say? Just like this:
NSLog(@"BOOL = %@\n", (boolVar ? @"YES" : @"NO"));
Then again, I don’t use NSLog anymore, I use DebugLog
Ever wanted to use NSLog in the iPhone SDK to see the value of a BOOL? Heck I have! “How do you do it”, you say? Just like this:
NSLog(@"BOOL = %@\n", (boolVar ? @"YES" : @"NO"));
Then again, I don’t use NSLog anymore, I use DebugLog
If you get the error “warning:comparison between pointer and integer”, odds are you are thinking right, but implementing your comparison wrong.
ur doin it wrong
if(count == 2) {
the right way
if([count intValue] == 2) {
NSLog is a convenient way to output logging information from your iPhone app. NSLog is most commonly used by developers for debugging purposes. The problem with adding NSLog statements in your code is that you have to remove them or comment them out before you can submit your application to the app store. Apps that output data via NSLog will not be approved into the app store.
I would like to show you how I handle this delema. Start by opening the “_Prefix.pch” file.
next, add the following lines to the file
#define DEBUG_MODE
#ifdef DEBUG_MODE
#define DebugLog( s, ... ) NSLog( @"<%@:(%d)> %@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )
#else
#define DebugLog( s, ... )
#endif
In your code, replace “NSLog” with “DebugLog”. THATS IT!
DebugLog adds some new functionality to NSLog. It will now output the file name and line number of the Debug statement.
The best part of this is that its very easy to disable when its time to create a release build of your code. Simple comment out the “#define DEBUG_MODE” line im the “_Prefix.pch” file.
This is how to get the version number of your app at run time. I find this helpful in to use in the “about” section of my apps. The version number is read from your apps info.plist file.
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
There are several ways to problematically detect if an iPhone has an internet connection, but most of them cant tell you how the iPhone is connected to the internet.
Apple has sample code to accomplish just this task. The Reachability class is not shipped with the SDK, but is part of a sample project of the same name. http://developer.apple.com/iphone/library/samplecode/Reachability/index.html
Set up:
Sample Usage:
Reachability *reachability = [Reachability sharedReachability];
[reachability setHostName:@"www.JoshHighland.com"];
NetworkStatus remoteHostStatus = [reachability remoteHostStatus];
if(remoteHostStatus == NotReachable) {
//no internet connection
}
else if (remoteHostStatus == ReachableViaWiFiNetwork) {
//wifi connection found
}
else if (remoteHostStatus == ReachableViaCarrierDataNetwork) {
//EDGE or 3G connection found
}