Cocoa versus Cocoa Touch - What is the difference?
Asked Answered
S

7

57

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?

Stacystadholder answered 19/2, 2010 at 16:25 Comment(0)
N
101

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.

Niddering answered 19/2, 2010 at 16:33 Comment(4)
There's one other difference: Cocoa is for Mac development; Cocoa Touch is for iOS development. If something is only in Cocoa, you can't use it on iOS, and if something is only in Cocoa Touch, you can't use it on Mac OS X.Rodomontade
Peter you should turn this into the answer.,Superstitious
@JimThio It wasn't Peter's question. Alexandru should be the one to mark it as answered.Niddering
Peter you should turn this into "an" answer. Sorry my mistake. Jasa's answer is great. Peter is more to the point of what it really is all about. At least he deserves upvotes.Superstitious
T
42

Application Framework For
i) Cocoa is the application framework for Mac OS X.
ii) Cocoa Touch is the application framework for iPhone and iPod Touch.

Frameworks
i) Cocoa: Foundation and AppKit.
ii) Cocoa Touch: Foundation and UIKit

Absence of certain classes
Cocoa has NSHost and Cocoa Touch doesn't

API
i) Cocoa: All the classes used in Cocoa have the NS prefix Ex: NSTextField
ii) Cocoa Touch: classes used in Cocoa have the UI prefix Ex: UITextField

MVC patterns
i) Cocoa: Cocoa has multiple alternative design patterns – in addition to MVC
ii) Cocoa Touch: The iPhone SDK has a reinforced MVC system, which performs better than the default MVC in Cocoa

Other Differences
There Are also Differences In App Lifecycle, Sandboxing ,Memory Footprint

Links:
http://teks.co.in/site/blog/cocoa-vs-cocoa-touch-beginners-guide/ http://iphonenativeapp.blogspot.in/2011/02/difference-between-cocoacocoa-touch-and.html https://iphonecodecenter.wordpress.com/tag/difference-between-cocoa-cocoa-touch/

Thereat answered 12/3, 2016 at 23:44 Comment(1)
You may want to name the source you summarised here: teks.co.in/site/blog/cocoa-vs-cocoa-touch-beginners-guide.Joiejoin
B
7

The Migrating from Cocoa Touch 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).

Beare answered 19/2, 2010 at 16:31 Comment(2)
The link is broken..then again, this was seven years ago.Manheim
Two weeks ago I got a Mac and I'm just trying to find out what all these cute names are. So the only thing that I can add that's useful is (for now anyway, give me a few weeks) don't click on the link, it's brokenManheim
G
5

In term of import in Swift

import Cocoa in Mac OSX application is the same as

import AppKit
import CoreData
import Foundation

whereas we can't import CocoaTouch in iOS

Galactic answered 19/1, 2016 at 3:1 Comment(2)
The question asks about what the difference between the frameworks are, not which ones can be imported where.Kidwell
Foundation is already part of AppKit. So no need to import it separately.Janes
N
2

1) Cocoa, which includes the Foundation and AppKit frameworks, is used for developing applications that run on OS X.

2) Cocoa Touch, which includes Foundation and UIKit frameworks, is used for developing applications that run on iOS.

Nidifugous answered 13/7, 2016 at 4:58 Comment(0)
D
2

Cocoa versus Cocoa Touch-

Cocoa - It is the application framework used for Mac OSX,

Cocoa Touch - It is the application framework used for iPhone and iPod touch

Cocoa - Foundation + AppKit Framework,
Cocoa Touch - Foundation + UIKIT Framework

Diverting answered 22/7, 2016 at 9:55 Comment(0)
C
0

Cocoa

NeXTSTEP -> Cocoa -> Swift Standard Library

[Swift Standard Library]

Cocoa is an application environment for iOS and OS X.

application environment is a set of

  • tools for developer: Xcode, Profiling, Command-Line Tool, development language(Objective-C)
  • runtime system: Objective-C runtime[About]
  • core libraries/frameworks
    • OS X: Foundation, AppKit, Core Data
    • iOS: Foundation, UIKit, Core Data

application environments :

  • OS X: Carbon, Cocoa
  • iOS: only Cocoa

Cocoa Touch is iOS layer which contains a set of libraries/frameworks for supporting iOS applications. For example - UIKit, MapKit...

*Usually Cocoa is considered as just a set of core libraries/frameworks

Cocoa framework is a framework with descendant classes of NSObject* which run under Objective-C runtime[About]

Frameworks with a Cocoa API - secondary frameworks which work with Cocoa frameworks and supports Cocoa conventions

Chavaree answered 24/9, 2022 at 16:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.