Wednesday, February 20

How to determine if an app is running in the iphone simulator?


If you want to determine if your app is running on the iPhone Simulator or on a device just put the following code somewhere in your app:
#if TARGET_IPHONE_SIMULATOR
    NSLog(@"Hey there! We're running on 'iPhone Simulator'");
#elif TARGET_OS_IPHONE
    NSLog(@"Attention please! We're running on an 'iOS Device");
#endif


This is also an easy way to put in some definitions. For example if the player should run faster on the simulator:
#if TARGET_IPHONE_SIMULATOR
#define MAX_PLAYER_SPEED 145.0
#elif TARGET_OS_IPHONE
#define MAX_PLAYER_SPEED 333.0
#endif

Saturday, August 11

How to count the lines of an Xcode project

The easiest way is to open the terminal app and navigate to the Xcode project and paste the following line:
find . "(" -name "*.m" -or -name "*.h" -or -name "*.mm" -or -name "*.cpp" ")" -print0 | xargs -0 wc -l
 You will get an result similar like this one:
count lines in xcode
terminal output

So now you know the lines per file and at the end the lines total of all the *.h and *.m files.