Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocoa versus Cocoa Touch - What is the difference?

I am learning iOS development in Objective-C, and I have found a lot of code examples.

Some of them, though, say that they are only for Mac OS X (not iOS).

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?

like image 879
Alexandru Luchian Avatar asked Feb 19 '10 16:02

Alexandru Luchian


People also ask

What is the difference between Cocoa and Cocoa Touch?

Both Cocoa and Cocoa Touch include the Objective-C runtime and two core frameworks: Cocoa, which includes the Foundation and AppKit frameworks, is used for developing applications that run on OS X. Cocoa Touch, which includes Foundation and UIKit frameworks, is used for developing applications that run on iOS.

What is Cocoa Touch class?

Cocoa Touch is a user interface framework provided by Apple for building software applications for products like iPhone, iPad and iPod Touch. It is primarily written in Objective C language and is based on Mac OS X. Cocoa Touch was developed based on model view controller software architecture.

What is Cocoa class in iOS?

Cocoa is a set of object-oriented frameworks that provides a runtime environment for applications running in OS X and iOS. Cocoa is the preeminent application environment for OS X and the only application environment for iOS.

What is the Cocoa framework?

Cocoa's Foundation framework provides many basic data types, including strings, arrays, dictionaries, and numbers. Foundation furnishes several classes whose purpose is to hold other objects—the collection classes. You'll learn more about these data types throughout the chapters in this book.


1 Answers

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’s and macOS’s, 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, for example, 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.

like image 96
Jasarien Avatar answered Sep 29 '22 06:09

Jasarien