Skip to content

Monthly Archives: January 2009

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]