Sunday, 28 November 2010

Why am I finding Objective-C and Cocoa difficult?

I have mainly been thinking about why the whole thing feels quite alien to me. I will use this post to remind me what the initial problems were. (Most are probably caused by several years of Python programming .. where most things are easy.)

Objective-C Pains
  • The syntax used to define a class seems awkward. And I hate repeating the method declarations in the .h and .m file.
  • I am having a real job remembering to add semi colons to every statement.
  • 12/06/2011: Memory allocation is something I have not had to worry about for a long time (good old Python).
  • More later...
Cocoa Pains

  • The GUI Api is not what I would call orthogonal. I seem to have to consult the documentation for each Controller. For example I would Expect the Api for a Label to be very similar to that of a Button. However, they differ even in the way they are created. The Label has to be allocated before inititalise with a frame, the Button does not have to be allocated and gets its frame later.
  • More later...

Monday, 22 November 2010

My first steps with XCode

Today I 'ave mainly been wondering about XCode and iPhone Apps.

The book I am reading suggests that it is a good idea not to use the interface builder. I am up for that, in fact I would be up for not using XCode if I thought it was easy enough.

These are the things you must do to avoid the Interface Builder:

  • File->New Project select Window-Based Application
  • Select Info.plist (from Groups and Files)
  • Right Click on Main nib file base line and select Cut
  • Right Click on the file MainWindow.xib (in Groups and Files)
  • Select Delete and Click on Also Move to Trash

The main.m file needs to look similar to this... (YourApp is the name of the .h and .m file containing the App code)

#import <UIKit/UIKit.h>

int main(int argc, char *argv[]) 
{
   NSAutoreleasePool * pool = 
      [[NSAutoreleasePool alloc] init];
   int retVal = 
      UIApplicationMain(argc, argv, 
          nil, @"YourApp");
   [pool release];
   return retVal;
}


You will also need to remove references to IBOutlet from the .h file.

Tuesday, 16 November 2010

iPhone Apps?

This week I have mainly been thinking about writing an App for iPhone.

To help me along I have been reading a book "Advanced iOS 4 Programming" by Maher Ali.

The initial hurdles to overcome are:

1. A new language: Objective C. and
2. A new Api for interacting with the OS and the device.

My first shock was how low level everything seems: writing in C and having to do your own memory allocation and garbage collection seems painful after a few years of Python. My second shock was the syntax of method calls. Its a mixture of square brackets and dots .... oh well I suppose its just syntax.

Will let you know how I get on!