Any suggestions on how to approach learning the Cocoa Touch API?
I'm an experienced programmer (C, a little C++, PHP, JavaScript) who is diving into developing for iOS. I have to say, while I get Objective-C with no problems, the Cocoa Touch API is massive, and quite complicated. Things that seem like they'd be simple, like dropping an annotated pin on a map, require several steps I would've never figured out without reading an example in a book.
I'm looking for suggestions on how to tackle learning this behemoth API. Let's say I wanted to figure out how to open a URL, fetch XML data from it, and parse it. How in the world would I even know where to begin (just an example, don't actually answer that)? I have Xcode 4, so I imagine the documentation must somehow make this rel开发者_如何学Goatively simple for me. I'm just new to this so I don't know where to start, so any advice would be stellar. Thanks.
Concentrate on the basics. Make sure that you read and fully understand the Memory Management Programming Guide. If you read SO for a while, you'll find that a large percentage of iOS-related questions come from people who obviously haven't read that document. The funny thing is that it's really not that complicated -- the answers to memory questions here are almost always the same, and almost always answered by this page.
Learn about the classes that are building blocks for the iOS apps. Know what UIResponder, UIView, UIControl, and UIViewController do, and how you can subclass them to do what you want. There are documents that explain all the important ideas, like views and view controllers. Read those: getting a feel for where to find information in the documentation will help you be productive much more quickly. View controllers give an app its visible structure, so it's important to understand how your own view controller objects are managed by container view controllers like navigation controllers and tab bar controllers.
Understand the important patterns, too: MVC is the philosophy that will guide you; delegation is used all over the place; chain of responsibility is used to handle events. Once you get the patterns, parsing an XML file, providing data for a table, and dropping pins on a map all start to make sense in the same way.
Stanford's excellent course CS 193P, "iPhone Application Development", is free in iTunes U.
The best way to learn it effectively is writing code with it. It takes lots of effort primarily because Apples API:s requires a different mindset than most other API:s you are probably used to, especially if coming from a PHP or JavaScript background.
The first hurdle to overcome is you have to accept the fact that many things you otherwise take for granted now requires lots of more code which you must write. A few examples to clarify:
- If you're coming from PHP then you are used to SimpleXML which requires just a few lines of code to use. In iOS, there is a SAX parser which requires much more effort and complexity to use.
- For activity indicator, there is something akin to an animated image which you can use, but you have to add your own label and code to make sure you block user touch events while the spinner is running.
- If you want a nice colored non-default non-round-rect-white button, you have to code it yourself. It's not hard, but it's definitely not like creating a CSS file.
So most (seemingly) simple tasks requires much more effort than you are probably used to.
The next hurdle is to mentally detach yourself from Interface Builder. IB may seem alluring and tempting at first, but one often ends up writing the GUI more or less in code anyway. For instance: UIPopovers, Navigation bars, transitions, tables and custom toolbars etc.
Another hurdle is UINavigationBar. When you truly understand how that works, you've come a long way! I'm not saying it is bad, just that it is very different from what you are probably used to.
Don't be ashamed of asking questions here and use google. Just reading books about it won't help though.
Please not this is not a criticism of the platform. Quite the opposite as I personally am very fond of it and understand the reason why it works the way it does (most of the time). It is just that many programmers starting out with iOS development has very high expectations how easy it is to start working with it, and ends up getting burned or frustrated.
精彩评论