Swipe gesture in UIAutomation

March 23rd, 2011

It took me a while to figure this out, but the key is that in your gesture coordinates, the values cannot result in a perfect translation left to right (and presumable up and down, but I didn’t test a vertical gesture.)

I use a horizontal swipe gesture on the navigationBar to bring up an alert that contains diagnostic information.

// Boiler plate code. var target = UIATarget.localTarget(); var application = target.frontMostApp(); var mainWindow = application.mainWindow(); // Swipe gesture to bring up console. var navigationBar = mainWindow.navigationBar(); navigationBar.dragInsideWithOptions({startOffset:{x:0.0, y:0.0}, endOffset:{x:0.8, y:0.10}, duration:0.1});

Reference: wiki

iOS Simulator detection

March 23rd, 2011

When working with iOS features that are only available on the devices and not in the Simulator, it can be helpful for testing to pop an alert or provide ‘stub’ data.

Fortunately there are some definitions provided by Apple to help identify what the code is targeted for.

#if TARGET_IPHONE_SIMULATOR // Code for simulator. #else // Code for device #endif

Reference: wiki

UIAutomation ‘typing’ on the keyboard

March 21st, 2011

I was looking for a way to use the iOS keyboard directly, Stack oveflow to the rescue again:

// Boiler plate code. var target = UIATarget.localTarget(); var application = target.frontMostApp(); var mainWindow = application.mainWindow(); var keyBoard=application.keyboard(); var keys = keyBoard.keys(); keys.firstWithName("g").tap(); target.delay(0.5); keys.firstWithName("o").tap(); target.delay(0.5); keys.firstWithName("r").tap(); target.delay(0.5); keys.firstWithName("d").tap(); target.delay(0.5); keys.firstWithName("o").tap(); target.delay(0.5);

Reference: stackoverflow wiki

Setting ORGANIZATIONNAME in Xcode

March 13th, 2011

When a new file is created in Xcode, there is a boiler plate copyright section at the top of the document, which by default is set to ‘ORGANIZATIONNAME’.

The easiest way to change this is to use the *defaults* app to write to the Xcode config:

defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{ORGANIZATIONNAME="Gordon Turner";}'

Works with Xcode 3.2.6.

Reference: wiki

Using gdb to print out Objective-C objects

March 7th, 2011

Sometimes the object that you want to debug is more complicated then an int or string.

In those situations, you will need to ‘pass a message’ to the object:

po (int)[textField superview]

Even then, there are occasions where you will have to use a selector:

print (int)[receivedData performSelector:@selector(count) ]

And finally, use a selector with an object as an argument:

print (int)[receivedData performSelector:@selector(count) withObject:myObject ]

Reference: stackoverflow wiki