views:

166

answers:

2

I am learning iphone/objective-c development and I find a lot of code examples.

Some of them though I only for MacOS.

Can someone please explain to me what is the difference between Cocoa and Cocoa Touch (at a library level), so that I know what code will work and what will not work.

Thank you.

+1  A: 

The Migrating from Cocoa section of the iPhone OS Technology Overview provides a good overview of the differences with links to more specific documents for each layer.

The big difference is the UI layer. On the Mac, you have the AppKit framework, on the iPhone, you have UIKit. The smaller differences are in the Foundation framework (linked in the document above).

Joshua Nozzi
+4  A: 

Cocoa is commonly referred to as the combination of the Foundation and AppKit frameworks, while Cocoa Touch is the combination of the Foundation and UIKit frameworks.

Cocoa and Cocoa Touch sit on top of other collections of frameworks to create the API stacks. The other layers are Media, Core Services and Core OS.

The main difference between Cocoa and Cocoa touch is that the UI classes and APIs aren't the same as Mac OS X, so instead of NSTextField, you have UITextField. Many of the classes share the same functionality and can be ported quite easily by simply changing the class name, though most will require some more changes, but usually nothing too heavy.

There are also some differences between the Foundation frameworks in Cocoa and Cocoa Touch, most commonly missing classes, eg, Cocoa has NSHost and Cocoa Touch doesn't.

You will come to know more of the nuances between the two and will soon be able to instinctively know what will work on an iPhone with little/no modification and what will require some work to port between, but it's not that difficult.

Jasarien