Sunday, March 8, 2009

Experimenting with iPhone development

I've begun experimenting with iPhone development. I have a MacBook Pro and I like the Cocoa development platform even though I'm less than trilled with the "Drink our koolaid or we'll send the zombies after you" attitude of the Mac community.

Honestly, Objective C isn't as big of a problem for me as I thought. Once I got the concept of sending messages to objects and the syncax, it's all good now.

Here is an example of an Alert dialog for agreeing to a license in Android and Cocoa:

Android:

new AlertDialog.Builder(AndroidExamples.this)
.setTitle("License Agreement")
.setMessage("EULA TEXT HERE")
.setNeutralButton("Accept", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//Handle click here
}
})
.setCancelButton("Decline", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//Handle click here
}
})
.show();

Cocoa:

UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"License Agreement"
message:@"EULA TEXT HERE"
delegate:self
cancelButtonTitle:@"Decline"
otherButtonTitles: @"Accept"
, nil];
[alert show];
[alert release];


There is a little more such as creating a handler to accept the button clicks. In COCOA, you create a delegate, and in Android you pass in a method (I usually do them dynamically).

I suppose you can argue either way, but I like that COCOA has a single event for the dialog and not for each button. You can do the same in Android by registering the same method for both or by putting the logic in a method and calling the method from the handler.

Either way, it's fun to learn a new language and platform so I'll continue to play around. My goal is to learn enough to port the My Collection application to the platform. I don't know if I'll sell it on the App Store but at least I'll learn something new.

No comments:

Post a Comment