views:

76

answers:

2

I have spent a lot of time getting into iOS development. I have spent a lot of time familiarizing myself with objective-c as well as xcode. I have spent a lot of time going through the motions without understanding the fundamentals of what Cocoa is.

I haven't grown up my entire life understanding coding concepts as some people have, and when people tell me that Cocoa is a framework, that doesn't really mean very much to me.

Can somebody undertake to explain IN SIMPLE ENGLISH what Cocoa is? What a framework is? How I as an aspiring developer should use it? What it should mean to me? I have spent so much time trying to understand it from definitions that don't make sense, that I wanted to try this and see if something could just click.

Thanks for your time

A: 

Think of a framework like a library. So let's talk in terms of books. A library is full of books! In this case, our books are our classes. Now books have pages that tell the story, and classes do too, they're called methods and properties.

So based on the above, we can tell that libraries contain classes which help us do things. A framework is just a packaged library really.

When you write things like:

NSObject* foo = [[NSObject alloc] init];

and later call:

[foo release];

what you're doing is using parts of Cocoa—specifically, memory management. +alloc is a class method which creates an object, and -init is an instance method (+ refers to class methods, - refers to instance methods—that's how they get defined in Objective-C code). Likewise, -release is used to release your ownership of the object you created previous.

These three methods are part of Cocoa. In the NSObject book.

I hope this is simple enough for you to understand.

jer
Hey thanks for your answer! It helped a lot. So what is the best way to sift through the books in the library? There are tons and tons of them in Cocoa right? Is it just a matter of looking for what you need?
Jeremy
There are plenty of tutorials, apple sample code, and built in documentation browser in Xcode. I recommend the book "Programming in Objective-C" by Stephen Kochan as well (second edition, it covers Objective-C 2.0).
jer
One thing of note, Jeremy, is that when programming iOS, you use the Cocoa Touch framework, not Cocoa. Cocoa is the Mac development framework (consisting of sub-frameworks Foundation, AppKit, and Core Data), whereas Cocoa Touch is the iOS development framework (consisting of sub-frameworks Foundation, UIKit, and Core Data). Even in the two sub-frameworks in common, there are differences between Cocoa Foundation/Core Data and Cocoa Touch Foundation/Core Data. These are called out in the documentation (usually something only available on one and not the other).
Peter Hosey
A: 

In addition to containing library routines, a framework usually forces your application into a certain paradigm, such as requiring your app to be structured in a certain way, and/or requiring a lot of defined subroutines/methods in your app that the framework can call. In fact, a framework such a Cocoa Touch can often call your app far more than your app might call any library code in the framework.

One good way of learning a framework is to read the source code of many example apps, and try to separate out the application logic from the framework glue.

hotpaw2