So I've gone back to developing software for the Mac and iPhone platforms. The first stop on my adventure was the Apple Developer Connection web site. The site is split into three parts: Mac Dev Center, iPhone Dev Center, and Safari Dev Center. There is a lot of really great material here but it's a bit difficult to get into. This is especially true if you're eager to get started.
My next stop was to search out for some good books. The first bunch of books I found was by Jonathan Zdziarski and published by O'Reilly. I first heard of Jonathan as a result of a Ignite Boston event. He gave a great talk about how insecure the iPhone was. That of course led me to take his course on iPhone Forensics and then picked up his three books: iPhone Forensics, iPhone Open Application Development, iPhone SDK. Out of this set the forensics book is scary because you can't unlearn that kind of stuff. The open app book is good but print has a hard time keeping up with the speed of the internet. Finally, the SDK book is good but I found that I needed to get even further back to basics.
The next book I found, which is still in development, is from Pragmatic Programmers called iPhone SDK Development. Being a beta book means that you can buy a digital copy or a digital copy now and a hard copy, when it's published. The book is ok but if you're coming at this raw then it's still a bit rough. This is especially true since sections of the book are still under development. With the release of the iPhone SDK 3.0 I think the authors are going to have a heck of a time capturing the 1000 new APIs in this book.
Finally, I decided to start with the very basics, Objective-C. I grabbed a copy of Learn Objective-C on the Mac by Mark Dalrymple and Scott Knaste. I learned how to program the Mac with Scott Knastes earlier book Macintosh Programming Secrets and so I figured this would be a good starting point. I was right. The book is a solid intro to Objective-C on the Mac and I would recommend it to anyone trying to get started.
It's funny, Objective-C really feels like going back in time now that I know Java. Having to write header files and dealing with memory management just seem so wrong now but such is life. Apparently the latest versions of Objective-C has auto memory management but it's only available for the Mac desktop and not the iPhone. If the iPhone only ran Java but it seems Apple is committed to using Objective-C.
So, once I got the basics of Objective-C I decided to dig a little deeper into Cocoa. Cocoa Programming for Mac OS X has been a very popular book on Cocoa, so I started there. I'm still reading the book but the start was good. It's interesting to see how Apple mixes code and interface design tools.
The problem I had/have was working out how an Mac app gets off the ground. Java has you create a class with a 'static main' and then pointing the Java VM to that class. My challenge was connecting the dots but I think I got it. Every Mac application has a main.m file which basically looks like this:
#import <cocoa/cocoa.h>
int main(int argc, char *argv[]){
return NSApplicationMain(argc, (const char **) argv);
}
Which to a Java developer looks weird. NSApplicationMain isn't something you write. It's a function that lives in the NSApplication file. Essentially it gets the ball rolling and stars the event loop. As I read the documentation on NSApplication and NSApplicationMain I found that it loads the 'main nib file' and that this nib file was something the developer could define. Looking at the Cocoa application project, that XCode creates, I could see only one nib, well really xib, file. The problem of course was that now I wanted to know where the heck this 'main nib file' was defined and how I could change it.
Well, a lot of digging on the net and I found the answer. As part of the Cocoa application project there is a file called info.plist. In the standard project tree the info.plist lives inside the Resources folder which lives inside your app folder. Inside this fun file lives all kinds of information about the application you're building. This file is a dictionary with keys and values. One of the entries just happens to be titled Main nib file base name. All you have to do is change the value of this entry and you're good to go.
So, that's that for now. I hope that someone else, trying to figure this out, finds this useful. More to come as I keep developing.
Thursday, March 19, 2009
Subscribe to:
Comments (Atom)