Last year I learned Ruby and Ruby on Rails. So in keeping with that good advice to learn a new program language every year, I thought this year I would tackle objective C and Apple's IDE (xcode). Why not? iPhones are fun and the only reason I was able to talk my wife into letting me fork out the money for a Mac was because I told her I wanted to write iPhone apps. Well, 3 years later and I'm finally doing it...
So here's how I'm starting:
Resources
As I've been researching the best book to buy or examples to find, I'm always struck by how readily information is available to any seeker of wisdom.
Books
There are lots of books about iPhone development and I read the first chapter of several of them. I ended up accidently clicking the
Beginning iPhone 4 Development: Exploring the iOS SDK from Amazon which I suppose wasn't bad since it seems to be the top recommended book. The book will probably arrive sometime this week. But as I checked out the first chapters of the one by the Big Nerd Ranch, I really liked how they presented and explained things. So that's it for books. O'Reilly has a deal today as well for $13 for a book called Cocoa & Objective-C: Up&Running . Its $14 with the 50% discount code of DDCRN. There seems no shortage of people who want to tell you how to code for the iPhone as long as you are willing to pay for it.
Apple Resources
I was able to download from Apple's iBook store the free
iOS Application Programming Guide, which was actually pretty well written and I'm sure I'll go back to. It is about 333 pages and tells how apps run on an i* device. Many of the concepts I'm sure I'll forget but hopefully when I run into a serious bug I'll come back to it and say doh! its cause of _______. I actually really like this doc (for now) as it provides a theory which is something a person who already knows how to program needs to get familiar with to get up and running on this platform. This is a huge recommendation. There are also several other Apple docs referenced in this pdf file that shouldn't be overlooked. Included in this is "The Objective-C Programming Language"
Videos
Here was where the real treasure chest was found. The course given at Stanford university is offered on
YouTube and is also available from iTunes complete with power point documentation. Watching the last half of the first class and I already created my first app with a slider that changes a label. The Stanford class doesn't use any books and instead references Apple documentation. It seems to be a great way to start learning. I figure if I do one lecture a day (or 1 every two days where I follow along ) then I'll be in very good shape.
Other Online Resources
In addition to iTunes U and YouTube there are countless other sites where people freely share information. Just google the class you want to know about and you're there. But how can you beat getting taught from Stanford professors who are also employees of Apple?
The first program
So after using xcode and generating the slider demo from the Stanford class I thought I'd first just try to compile using good old gcc and a basic program. There was a good wiki article that explained the history of the language. One of the important things I read was: "In Objective-C one does not
call a method; one
sends a message" so as a future reference, I have to remember that objects are sent messages to run what would be a method in most normal OOP languages. The other few important things:
- Classes are declared in header files and methods are implemented in the *.m files (which used to stand for messages)
- In the header file a (-) in front of a method means its an instance method. A (+) in front of the method means its a class method (similar to how in Ruby we do a self.foo)
So here's a program named nothing.m that does nothing:
#import <Foundation/Foundation.h>
int main(){
return 0;
};
Then, I just compile it on the command line:
gcc -framework Foundation nothing.m -o nothing
Running nothing:
./nothing
Not very interesting, but hey, its a program and it did what you told it to do. You can then get fancy and add a printf or something else. But from here on out, I'll probably be in xcode as that seems to be what all the cool kids are doing.
What are some important beginner tips you have?