|category||Framework , programming interface|
Cocoa programs are mostly those with a graphical user interface ( GUI ), but the development of e.g. B. command line tools or daemons possible. Typically, development takes place with the help of the “ developer tools ”, which Apple has made available free of charge up to version 3.2 after registering by name and which essentially consist of the IDE Xcode (predecessor: Project Builder ) and the Interface Builder . Xcode can be downloaded free of charge from the Mac App Store or - as a registered developer - from the Apple Developer Homepage.
Objective-C and Swift are the primary programming languages ; C ++ and C can basically be used within a project. Alternatively, programming from Java is possible (with restrictions) . However, Apple no longer supports the Java-Cocoa Bridge. There are also Cocoa interfaces for other languages, such as PerlObjCBridge (for Perl ) or the open source projects PyObjC (for Python ) and RubyCocoa (for Ruby ), FPC PasCocoa (for Lazarus and Free Pascal ) and Cocoa # (for C # or mono ). Since the Mac OS X Tiger (10.4, 2005) the Cocoa framework Core Data has been using the SQLite database . Mac's own scripting language AppleScript can be used to implement simple actions and routines.
Cocoa was initially the name for a multimedia development environment written in Sk8 from Apple for children, which was later continued by the Stagecast company under the name Stagecast Creator .
Today's Cocoa is a further development of the NeXTStep programming interface , which was developed by the NeXT company in the late 1980s . This was initially used in the operating system of the same name, which was distributed on the company's own computers. At the beginning of the 1990s, however, NeXT was forced to leave the hardware business and the NeXTstep API was also sold on other systems as OpenStep . Similar to Java , an OpenStep program could have run natively on many different operating systems and would have been " source-code- compatible" on different processor architectures . OpenStep was not only the programming interface of OPENSTEP , it was also ported by Sun Microsystems for its own Solaris operating system (OpenStep for Solaris) and by NeXT for Windows NT (OPENSTEP Enterprise) as an attachment for the respective operating system.
Since OpenStep was published by NeXT and Sun as an open specification, the API in the GNUstep project could also be reprogrammed for other operating systems.
In 1996, NeXT was bought by Apple, where OpenStep was renamed Yellow Box, further developed and continued to be offered for Windows NT. Yellow Box was supposed to be the new programming interface for the successor operating system of the classic Mac OS , developed under the name Rhapsody , but the providers of indispensable application software for Mac OS reacted cautiously after the presentation of Apple's plans at WWDC 1997, as they put all their programs at great expense should have ported from the Macintosh API to Yellow Box.
After MacWorld 1998, Yellow Box was abandoned as a cross-operating system programming interface together with Rhapsody. Instead, Yellow Box became the API of the upcoming Mac OS X operating system , where it was renamed Cocoa. Thus existing Macintosh applications could also take on the new operating system feet, was charged with carboxylic introduced another API (renamed from 1997 in Mac OS) called on the programming of the introduced 1984 "System" Macintosh operating system and its toolbox-ROM -based . Existing Mac OS applications for System 7 and Mac OS 8 could be recompiled for Carbon with only minimal adjustments . The result could be executed natively on Mac OS X as well as Mac OS 8 and 9 . However, Carbon and Cocoa are not compatible and only Cocoa offers the advantages of a modern operating system with memory protection , preemptive multitasking and multi-processor capability . Most Mac application programs were therefore fully ported from Carbon to Cocoa during the 2000s.
NeXTstep, OpenStep and Yellow Box are the historical ancestors of the Cocoa programming interface of macOS (the name of Mac OS X / OS X since 2016) and iOS . With GNUstep there is a complete OpenStep and an incomplete Cocoa API as open-source post-programming.
Cocoa consists of three frameworks :
- Foundation provides all relevant base classes (strings, arrays, memory management, iterators, etc.).
- AppKit (formerly Application Kit ) contains classes for developing graphical user interfaces, for example windows, buttons or menus.
- Core Data (since Mac OS X Tiger , 10.4, 2005) for creating object graphs.
The classes of the Cocoa framework mainly begin with the letters "NS", such as NSObject, NSArray or NSString, which stands for N eXT S tep from which the API of the same name NeXTstep and later the OpenStep specification emerged.
macOS provides additional frameworks, but they are not a direct part of Cocoa:
- WebKit , a KHTML -based HTML renderer , the base of the Apple browser Safari is
- AddressBook for communication with the system address book
- Core image , core animation
These frameworks roughly correspond to dynamically loaded object libraries ( DLL / DSO ), but in contrast to DLLs also contain the access mechanisms in the form of "header files". They are available as compiled object files on macOS.
The Foundation classes provide a basis for programming with Objective-C. It mainly includes:
- The storage management system reference counting
- The exception system (NSException)
- The base classes for basic types such as strings, values, and dates
- Collection classes for quantities, lists and maps
- File handling including web-related functionality
- XML support
- Undo function
AppKit implements the most important infrastructure for applications, i.e. programs with a graphical user interface:
- Application infrastructure including pre-setting system
- Event operation
- Elements of the graphical user interface such as windows, views and menus
- Elements of the controller layer
- Voice connections
- Text system (strings with attributes)
Core Data represents a modeling and persistence layer with automatic support for Undo functionality. It is used for the rapid 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
Cocoa pursues a few concepts tailored to the dynamic structure of Objective-C. This should also be the reason why Java is no longer supported. Due to the static structure (static typing, early binding) of Java, the structures of Cocoa can only be implemented there to a limited extent or with great effort.
On the one hand, the MVC pattern is strictly implemented in Cocoa, so that most classes can be clearly assigned. On the other hand, the effort that results from this is alleviated through support. For example, bindings allow the automatic synchronization of model values in all relevant views without the application programmer having to write code.
Some classes of Cocoa only represent the visible part of the iceberg. In fact, they are never instantiated, but rather instances of suitable but hidden subclasses are created at runtime. For example, the application programmer requests an instance of NSArray but, depending on the number of elements, receives an instance of a class that he does not know.
In principle, activities that burden the system are only carried out when they are necessary. This is how instances of the "NSImage" class model images. The image data are only loaded when they actually have to be known for an operation; the model is only loaded then and only to the extent necessary for the current operation, etc.
Event operation and responder chain
Cocoa applications are strictly event-driven. Every activity of an application takes place on the basis of an external event. Events run through a so-called "responder chain", the links of which are objects of different classes. Each of these members can take an event that has occurred and answer it or pass it on to the next member.
Implementations outside of Mac OS X / OS X / macOS
In addition to the Cocoa API from Apple contained in Mac OS X / OS X / macOS, there is also a free , cross-platform implementation called GNUstep . This simulation is used to port application programs for Mac OS X to other operating systems without great effort . In contrast to Windows applications under Wine , it is usually not possible to run applications compiled for Mac OS X. GNUstep does not contain all of the features of Cocoa, which can make porting easy. Especially if the applications depend on other APIs from Mac OS X, such as Carbon , in addition to Cocoa , porting can be very complex despite GNUstep. Since Mac OS X itself a unixoides system, the implementation of GNUstep is in Linux - and Unix systems easier and more slender than in Windows where first with MinGW must provide the necessary minimal Unix-like functionality.
- Amin Negm-Awad, Christian Kienle: Objective-C and Cocoa Volume 2: Advanced . 1st edition. SmartBooks Verlag, 2010, ISBN 978-3-908497-84-4 .
- Amin Negm-Awad, Christian Kienle: Xcode, Objective-C and Cocoa . In: Horst-Dieter Radke (Hrsg.): Automation and application development on the Mac - introductions . 1st edition. SmartBooks Publishing, 2009, ISBN 978-3-908497-98-1 .
- Amin Negm-Awad: Objective-C and Cocoa Volume 1: Basics . 3rd / 5th Edition. SmartBooks Verlag, 2012, ISBN 978-3-908498-08-7 .
- Aaron Hillegass: Cocoa Programming for Mac OS X . 3. Edition. Addison-Wesley Longman, Amsterdam / Upper Saddle River NJ 2008, ISBN 978-0-321-50361-9 .
- Aaron Hillegass: Cocoa Programming for Mac OS X . Translation of the 3rd edition. mitp-Verlag, Frechen, 2008, ISBN 978-3-8266-5960-7 .
- Scott Anguish, Eric M. Buck, Donald A. Yacktman: Cocoa Programming . Sams, 2002, ISBN 978-0-672-32230-3 .
- James West Davidson: Learning Cocoa with Objective-C . O'Reilly, Beijing 2002, ISBN 0-596-00301-3 .
- Daniel H. Steinberg: Cocoa programming: The quick start for developers . 1st edition. O'Reilly, 2010, ISBN 978-3-89721-613-6 .
- Holger Hinzberg: Modern Objective-C and Cocoa Practical introduction: Programming for Mac OS X and iPhone . 3. Edition. mitp-Verlag, Frechen 2014, ISBN 978-3-8266-9701-2 .
- Holger Hinzberg: Mac programming for kids . 2nd Edition. mitp-Verlag, Frechen 2011, ISBN 978-3-8266-8684-9 .
- Introduction to Cocoa Fundamentals
- cocoading - German language page for the book "Objective-C und Cocoa"
- CamelBones (Cocoa for Perl)
- PyObjC (Cocoa for Python)
- Wikibooks: Programming: Cocoa
- ObjectiveCeeds - Technical article on Cocoa programming