Skip to content

Category Archives: Xcode

Xcode is a suite of tools for developing software on Mac OS X, developed by Apple. Xcode 3.0, the latest major version, is bundled free with Mac OS X v10.5, though it is not installed by default. The main application of the suite is the integrated development environment, also named Xcode. The Xcode suite also includes most of Apple’s developer documentation, and Interface Builder, an application used to construct graphical interfaces. – Wikipedia

Accelerometer setup and usage

To use the accelerometer in an iPhone application you need to add the <UIAccelerometerDelegate> into the .h file of your application: [code lang="c_mac"]@interface ApplicationViewController : UIViewController {[/code] Then in your .m file you must setup the accelerometer: [code lang="c_mac"] - (void)viewDidLoad { UIAccelerometer *accel = [UIAccelerometer sharedAccelerometer]; accel.delegate = self; accel.updateInterval = 1/30; } [/code] [...]

Creating and using an Array of objects

First we need an array to hold the objects (in this case bullets) [code lang="c_mac"] NSMutableArray *myBullets = [[NSMutableArray alloc] init]; [/code] Create and then add the objects [code lang="c_mac"] for (int i=0; i

Changing the iPhone status bar

Just use this code to change the type of status bar shown. Stick it in the applicationDidFinishLaunching method which is usually in your MyAppDelegate.m [code lang="c_mac"] [application setStatusBarStyle:UIStatusBarStyleBlackOpaque]; [/code]

Round a number

To round a number use the following code: [code lang="c_mac"] CGFloat variable = ... CGFloat result = round(variable * 1000.0) / 1000.0; [/code] or [code lang="c_mac"] CGFloat variable = round(variable * 1000.0) / 1000.0; [/code] Use 1000 for 3decimal places, 100 for 2 etc!

Objective C Timer

This is a simple timer, you may need to declare some variables in the .h file. [code lang="c_mac"] -(void)onViewDidLoad { //set on start up NSDate *startTime = [NSDate date]; } [/code] [code lang="c_mac"] -(void)someOtherFunction { //amount to dely by (seconds) NSInteger *delayAmount = 1; //work out the current delay time NSTimeInterval elapsedTime = [startTime timeIntervalSinceNow]; [...]

String to Number (integer)

To convert a string of a number (“568″) to a integer (568): [code lang="c_mac"] //aString = "568" NSInteger *aNSintegerNumber = [aString integerValue]; //aNumber =568 [/code] or [code lang="c_mac"] //aString = "568" int *aIntNumber = [aString intValue]; //aIntNumber = 568 [/code]