Cocoa (API)

Cocoa [ koʊkoʊ ] (english cocoa "Cocoa " ) is an object- oriented programming interface for programming on the Mac OS X from Apple.

Cocoa applications are usually those with a graphical user interface ( GUI), but it is also the development of, for example, command-line tools or daemons possible. Typically, the development is done using the "Developer Tools" that Apple has made by roll-call registry up to version 3.2 free of charge and which consists essentially of the Xcode IDE (predecessor: Project Builder ) and consist Interface Builder. Xcode can be downloaded for free from the Mac App Store, or - as a registered developer - also from the Apple Developer website.

The primary programming language there is the technology based on Smalltalk Objective- C ( an object-oriented superset of C); C and C are generally used within a project. Alternatively, the programming (with restrictions) from Java possible. Apple, however, no longer supports the Java Cocoa Bridge. Furthermore, there are Cocoa interfaces for other languages ​​, such as PerlObjCBridge ( for Perl) or the open- source projects PyObjC ( Python ) and RubyCocoa ( for Ruby ), FPC PasCocoa ( for Lazarus and Free Pascal ) and Cocoa # (for C # or mono). Since the operating system version 10.4, the Cocoa Framework Core Data uses the database ( SQLite). The Mac own scripting language, AppleScript can be used to implement simple actions and routines.

  • 3.1 Model-View- Controller
  • 3.2 Class Clusters
  • 3.3 Laziness
  • 3.4 Event operation and responder chain

History

Cocoa was first written in the name of a Sk8 multimedia development environment from Apple for children, which was later followed up by the company Stagecast under the name Stagecast Creator.

Today's Cocoa is a further development of NeXTStep and OpenStep, which was developed by company NeXT in the late 1980s.

After the appearance of a beta version of Safari for Windows in June 2007 there were rumors that Apple (again) working on a port of Cocoa on the Windows platform.

Frameworks

Cocoa consists of three frameworks:

  • Foundation provides all relevant base classes (strings, arrays, memory management, iterator, etc. ) are available.
  • Application Kit contains classes for the development of graphical user interfaces, such as windows, buttons or menus.
  • Core Data (since Mac OS X 10.4 - " Tiger") for the creation of object graphs.

The classes of the Cocoa frameworks mainly start with the letters NS, such as in NSObject, NSArray or NSString. This acronym stands for the OpenStep framework NeXTStep, which was purchased by Apple in 1996 and used as the basis for Mac OS X.

Mac OS X provides with other frameworks, but they are not direct components of Cocoa:

  • WebKit HTML renderer, which form the basis of the Apple Safari browser (see also HTML rendering )
  • Address Book for communication with the system address book
  • Core Image, Core Animation

These frameworks are similar to the dynamically loaded object libraries ( DLL / DSO), but which contain unlike DLLs and the access mechanisms in the form of " header files ". , You are under Mac OS X as a compiled object files. Most of the frameworks of which consists Cocoa, have not yet been released by Apple in the source code.

Foundation

The classes of the Foundation provide a foundation of programming with Objective- C. Included are mainly:

  • The memory management system of reference counting
  • The exception system ( NSException )
  • The base classes for basic types such as for strings, values ​​and data
  • Collection classes for sets, lists and maps
  • File handling including webbezogener functionality
  • XML Support
  • Undo function

AppKit

AppKit implements the most important infrastructure for applications, which are programs with graphical user interface:

  • Application infrastructure, including setting system
  • Event operation
  • Graphical interface elements such as windows, views and menus
  • Elements of the controller layer
  • Language bindings
  • Text system ( strings with attributes )

Core Data

Core Data provides a modeling and persistence with automatic support for undo functionality dar. It is used for fast design of models in the system of the Model-View- Controller pattern. Core Data includes support for:

  • Description of the model structure
  • Storage of data
  • XML and SQLite

Concepts

Cocoa followed some concepts, which are tailored to the dynamic structure of Objective-C. This is probably also the reason why Java is no longer supported. Due to the static structure ( Static Typing, Early Binding) of Java, the structures of Cocoa let there be restricted or implement but at great expense.

Model-View- Controller

On one hand, the MVC pattern is implemented strictly in Cocoa, so that can be most clearly assigned classes. On the other hand, the following expenses therefrom is alleviated by support. So allow about bindings automatic synchronization of model values ​​in all relevant views, without requiring the application programmer must write this code.

Class Clusters

Some classes of Cocoa represent only the visible part of the iceberg dar. fact they are never instantiated, but rather at run-time instances matching, but hidden subclasses generated. For example, the application programmer asks for an instance of NSArray, but receives an instance of a class that he does not know, depending on the number of items.

Laziness

Basically, the system onerous activities will only be made ​​when they are necessary. To model instances of the class " NSImage " images. The image data are, however, only charged when they must be actually known to an operation; The model is only loaded and only insofar as is necessary for the current operation, etc.

Event operation and responder chain

Cocoa applications are strictly event-driven. Any activity of an application made ​​under an external event. Events through a so-called " responder chain " consisting of different classes and take a eingetroffenes event and process - or not.

Implementations outside of Mac OS X

In addition to the information contained in Mac OS X Cocoa API from Apple, there is also a free, cross-platform implementation called GNUstep. This replica is used to port application programs for Mac OS X with little effort for other operating systems. Running compiled for Mac OS X applications, unlike Windows applications under Wine, usually not possible. GNUstep does not contain all the features of Cocoa, which can make it easy to port. Especially when the applications in addition to other Cocoa APIs of Mac OS X, such as carbon are dependent, the porting can be very costly despite GNUstep. Since Mac OS X is a unixoides system itself, the implementation of GNUstep on Linux and Unix systems is simpler and more streamlined than in Windows, where first the necessary minimal Unix-like functionality must be provided with MinGW.

73178
de