02 January 2012

Developing Apps for Mac OS X With Objective-C and Cocoa



Even though I've used Macs for over 20 years now, I have never developed a native app for the Mac OS. So over the holiday break, I finally spent some time getting ramped up on Objective-C to develop apps for Mac OS X and IOS. This meant reading a lot about Objective-C, XCode and Cocoa.

I'm primarily a Java developer these days but I'm familiar with writing C code (though I haven't written it in many years) so this knowledge helped me quite a bit. The syntax for Objective-C was a bit strange at first but I got the hang of it after a bit and I'm continuing to learn. I managed to develop a command line app and a GUI app using XCode. Building the command line app was much more understandable for me because you are writing all the code by hand. Constructing the GUI app was a rather nebulous task mainly because you rely upon the IDE to handle many things for you. XCode is the IDE for building Objective-C apps for Mac OS X and IOS. When developing a GUI app, XCode provides a visual tool called Interface Builder that is amazing. It provides a standard set of widgets for your apps and allows you to do visually design the UI. Interface Builder simplifies the creation of connections from the code to the GUI widgets via dialogs and selections in those dialogs. Because the actual code to handle these things is hidden behind the IDE, the experience was rather cloudy in my mind. At some point, I plan to dig down into what is actually happening behind the curtain here to solidify it in my mind. I also used the XCode debugger and profiler which were both very nice tools and were both included in the IDE.

I forgot to mention that I am using Objective-C 2.0 and XCode 4.2. This is not only a new release of Objective-C but it's also a new release of XCode with a dramatically improved set of functionality. My prior experience was with XCode 3.x, it was minimal and I was not writing Objective-C, so I didn't really get to experience the power of XCode. Now that I've been through a couple of tutorials with XCode 4.2 and Objective-C, I must say that I'm duly impressed. In fact, Eclipse could stand to learn a few things from XCode. Objective-C 2.0 is a big improvement over the previous version. There's now automatic reference counting to help you with memory management (the big thing I hated about C/C++) and much more.

The apps I created run on Mac OS X. They are both very minimal and not very useful overall, but it is invigorating to delve into new territory for a platform that I have known and loved for over 20 years already. I plan to keep at it as time allows and build some useful apps. Perhaps I will even develop some IOS apps.

For those who are interested, here are the two tutorials that I followed:

I've also been reading many blogs from Objective-C and Cocoa developers. I also found some items for Java developers who want to learn Objective-C:

I will try to keep adding info about resources here as I think about them. Not only is this a record for myself, but hopefully it will help other folks as well.

8 comments:

  1. I've just started out on iOS 5 development with Xcode by following Paul Hegarty's (of Stanford) free course on iTunes U ( http://news.stanford.edu/news/2011/november/itunes-apps-class-111511.html ). The course materials are awesome, with video lectures, presentation slides, walkthroughs, and weekly assignments.

    It's fun on two fronts: discovering the whole Xcode + ObjC + iOS development process, and thinking (daydreaming) about making a killing on the App Store by writing the next must-have app :-)

    How's it going for you?

    ReplyDelete
  2. Yawar, Unfortunately I haven't had the time to dig back into Objective-C/XCode recently, but as of this week I should have more time to do so. I'm happy to hear that you are digging into this area. I hope that some of the resources that I noted will help you out.

    You bring up a very good point with regard to iTunes U. I viewed a couple of courses on ITunes U some time ago, but I was just kind of sampling them instead of following along and coding with the instructor. I know that there are several courses there focused on Objective-C and Cocoa on IOS and Mac OS X. I should go back there and look up some courses. Thanks for the reminder!

    ReplyDelete
  3. I've had those Apple reference pages and others open in my browser pretty much all weekend; but I don't come from a Java background so not so much the others.

    The thing I like about the iTunes U course is I'm working in a structured way (watch this video, read these notes, then try to solve that problem) instead of browsing through an amorphous cloud of websites and books trying to figure out what to absorb in what order. But since it's completely self-paced, there's no pressure and it's fun. I even get to laugh (a little bit) at the poor Stanford students as Hegarty tells them over and over to _not_ fall behind in the coursework because then they might as well drop out :-)

    ReplyDelete
  4. Agreed, that can be a nice way to get started. I tend to stray from that format pretty quickly because I've been creating software for a long time. Pretty quickly after getting started and having some success with a new language, I start to get ideas that are not covered in such training, so I go hunting through APIs trying to figure out how to do something. I wonder if the Stanford students Hegarty is addressing are comp sci students or not?

    ReplyDelete
  5. As for the students, the prerequisites for CS193P ( http://scpd.stanford.edu/search/publicCourseSearchDetails.do?method=load&courseId=1270571 ) seem like they could be fulfilled by either comp sci or software engineering students.

    ReplyDelete
  6. Awesome post. I added it with this list of resources. http://www.verious.com/board/sebastian.schepis/iphone-application-development/Keep up the good work.

    ReplyDelete
  7. The URL for My First Mac App has changed to https://developer.apple.com/library/mac/referencelibrary/GettingStarted/RoadMapOSX/books/RM_YourFirstApp_Mac/Articles/Introduction.html

    ReplyDelete
  8. Hello I’ve been developing Apps for iOS since couple of year,Now I would like to start developing apps for OS X .I’ve experience with Objective_C and Xcode IDE,Looking for first pace,for that help is needed .It would be nice and appreciate if you help me out with OS X.

    ReplyDelete