How to learn Cocoa

This is something any experienced Cocoa developer has been asked at least half a dozen times:

"What’s the best way to learn Objective-C/Cocoa?"

I have two answers to this question:

  1. Be curious
  2. Don’t be satisfied

Be Curious

Curiosity is the heart of learning anything. If you can cultivate a deep curiosity about the Objective-C language and the Cocoa frameworks, then I guarantee that you will have absolutely no problem learning them. I’m not talking about the “oh, wouldn’t it be nice to know how to write iOS apps” kind of curiosity. I’m talking about the “why does the @ sign go there? What’s up with these asterisks all over the place? Why are things done in this order instead of that order” kind of curiosity. Gaining this level of curiosity can be very difficult, especially at first. But without it, you’ll never really understand how everything is working together.

If you’re familiar with an sort of object-oriented programming language, then Objective-C, as a language, shouldn’t be that hard to pick up. Just use get used to the square brackets, and things will look pretty familiar. Learning the frameworks, on the other hand, will take a lifetime. The Cocoa Frameworks (Foundation, AppKit/UIKit, CoreData, CoreFoundation, MapKit, QuickLook, MediaAccess, CoreLocation, etc) are enormously broad. The Foundation framework itself is composed of 173 public classes and 31 protocols. That’s a lot of pre-built code, and that’s just one framework out of a couple dozen! There are some classes you will come to know very intimately (NSString, NSArray, NSDictionary), but even they will surprise you every now and then. Plus, Apple actively develops these frameworks; they’re being improved and optimized and expanded all the time. There will always be more to learn.

Along with the capabilities of the classes, there are patterns to learn. Design patterns describe how classes interact with each other. Some of the first ones you’ll encounter are Model View Controller, Delegation, and Class Clusters. There are many others, and they’re in there for a very good reason. As you come across them, take the time to understand why they’re there.

Do the same with the classes in the frameworks. Explore them. Play with them. Abuse them. Ask yourself:

  • What problem does this solve?
  • How does it solve the problem?
  • Can you use these abilities for anything else?
  • How would you implement this class if you had to? (And then go do it!)

Be curious.

Don’t Be Satisfied

As you learn Cocoa, the code you write will be terrible. Understand that. But don’t accept it. There is always a different way you could do something, and quite often one of those different ways is a better way. Always seek out opportunities to improve your code and to find different and better ways to organize it. Sometimes this will mean rewriting things half a dozen times. But you know what? That’s OK! All developers experience this. If you can learn to not be satisfied with your code, you’ll quickly learn how to iterate over it and make improvements here, tweak some stuff there, maybe rip out some layer of control and totally reorganize it… This is what programming is all about. Don’t be satisfied with how your code looks. Strive to make it a work of art and a thing of beauty.

Final Thoughts

So there you have it! These are my recommendations for how to learn Cocoa. They have served me well, and I think they pretty much summarize what I’ve observed about experienced developers.

Oh, and by the way…

  1. Know what a pointer is.
  2. Memorize the memory management rules.
  3. Never invoke -retainCount.

Welcome to Cocoa.

  1. metaphysical-insight reblogged this from funwithobjc
  2. jacknutting reblogged this from funwithobjc
  3. artoflivingrealty reblogged this from funwithobjc
  4. casque-monster-beat reblogged this from funwithobjc
  5. thomas-1984 reblogged this from funwithobjc
  6. bellimbusto2 reblogged this from funwithobjc
  7. first-grade-reading reblogged this from funwithobjc
  8. white-curtains reblogged this from funwithobjc
  9. candles-holders reblogged this from funwithobjc
  10. floor-pillow reblogged this from funwithobjc
  11. grill-grates reblogged this from funwithobjc
  12. mixer-blender reblogged this from funwithobjc
  13. cricket-franchise reblogged this from funwithobjc
  14. cricket-master-dealer-chicago reblogged this from funwithobjc
  15. boynton-beach-real-estate reblogged this from funwithobjc
  16. 1weddingfashion reblogged this from funwithobjc
  17. comohacercrecerelpene reblogged this from funwithobjc
  18. hot-to-seo reblogged this from funwithobjc
  19. bug-repellent reblogged this from funwithobjc
  20. quick-foods reblogged this from funwithobjc
  21. soda-drinks reblogged this from funwithobjc
  22. asvab-test reblogged this from funwithobjc
  23. funwithobjc posted this
Short URL for this post:
blog comments powered by Disqus