Mac Developer Library Developer

Survey the Major Frameworks

A framework is a directory that includes a shared library, header files to access the code stored in that library, and other resources such as image and sound files. A shared library defines functions and methods that apps can call.

OS X provides many frameworks that you can use in app development. To use a framework, add it to your project so that your app can link to it. Most apps link to the Foundation, AppKit, and Core Graphics frameworks. Depending on which template you choose for your app, other frameworks might also be included. You can always add additional frameworks to your project if the core set of frameworks does not meet your app’s needs.

To look at the frameworks included in TrackMix.xcodeproj
  1. Open the TrackMix.xcodeproj project in Xcode (if it’s not already open). You created this project earlier in the tutorial Your First Mac App.

  2. Open the Frameworks folder in the project navigator by clicking the disclosure triangle next to it.

  3. Open the Other Frameworks folder by clicking the disclosure triangle next to it.

    You should see AppKit.framework, CoreData.framework, and Foundation.framework. Even though you did not use Core Data in this project, these three frameworks are included as part of the umbrella Cocoa framework.

  4. You can view the header files in a framework by clicking the disclosure triangle next to the framework and then clicking the disclosure triangle next to the Headers folder.

Each framework corresponds to a layer of the OS X system. Each layer builds on the ones below it. Use higher-level frameworks instead of lower-level frameworks whenever possible. Higher-level frameworks provide object-oriented abstractions for lower-level constructs. These abstractions usually reduce the amount of code you have to write.

image: ../Art/frameworks_layer.png

OS X Apps Are Based on the Foundation and AppKit Frameworks

When you begin programming, you mainly use the Foundation and AppKit frameworks because they cover most of your app development needs.

The Foundation Framework Provides Basic System Services for All Apps

Your apps, as well as AppKit and other frameworks, are built on the Foundation framework infrastructure. The Foundation framework provides many primitive object classes and data types, making it fundamental to app development. It also establishes conventions (for tasks such as deallocation) which makes your code more consistent and reusable.

Use Foundation to:

  • Create and manage collections such as arrays and dictionaries

  • Create and manage strings

  • Access images and other resources stored in your app

  • Post and observe notifications

  • Create date and time objects

  • Automatically discover devices on IP networks

  • Manipulate URL streams

  • Execute code asynchronously

The AppKit Framework Provides Classes to Create a Graphical, Event-Driven User Interface

All Mac apps are based on AppKit. You can’t ship an app without this framework. AppKit provides the infrastructure for drawing to the screen, handling events, and creating common user interface elements. AppKit also organizes a complex app by managing the content that is displayed onscreen.

Use AppKit to:

  • Construct and manage your user interface

  • Handle user events

  • Present fonts, colors, and images

  • Perform basic animation

  • Support basic app features such as Spaces, Help Support, and multiple user accounts

  • Create custom user interface elements

In Your First Mac App, you used AppKit. You implemented the NSApplicationDelegate protocol to call updateUserInterface. In fact, you used AppKit to create your entire interface with the NSTextField and NSSlider classes.

Other Important Frameworks You Should Know About

The Core Data, Core Graphics, Core Animation, and OpenGL frameworks are advanced technologies. Although these frameworks are important for app development, they require time to learn and master.

The Core Data Framework Manages the Data Model of an App

Core Data provides object-graph management. With Core Data, you create model objects, known as managed objects. You manage relationships between those objects and make changes to the data through the framework. Core Data takes advantage of the built-in SQLite technology to store and manage data efficiently.

Use Core Data to:

  • Save and retrieve objects from storage

  • Support basic undo/redo

  • Validate property values automatically

  • Filter, group, and organize data in memory

  • Manage results in a table view with NSFetchedResultsController

  • Support document-based apps

The Core Graphics Framework Helps You Create Graphics

High-quality graphics are an important part of all OS X apps. The simplest and most efficient way to create graphics in OS X is to use prerendered images with the standard views and controls of the AppKit framework and let OS X do the drawing. AppKit also provides classes for custom drawing—including paths, colors, patterns, gradients, images, text, and transformations. Use AppKit, a higher-level framework, instead of Core Graphics, a lower-level framework, whenever possible.

Use Core Graphics when you want to write drawing code that you share directly between iOS and OS X. The Core Graphics framework, also known as Quartz, is nearly identical on both platforms.

Use Core Graphics to:

  • Make path-based drawings

  • Use antialiased rendering

  • Add gradients, images, and colors

  • Use coordinate-space transformations

Core Animation Allows You to Make Advanced Animations and Visual Effects

AppKit provides animations that are built on top of the Core Animation technology. If you need advanced animations beyond the capabilities of AppKit, you can use Core Animation directly. The Core Animation interfaces are contained in the Quartz Core framework. With Core Animation, you create a hierarchy of layer objects that you manipulate, rotate, scale, transform, and so forth. By using Core Animation’s familiar viewlike abstraction, you can create dynamic user interfaces without having to use low-level graphics APIs such as OpenGL.

Use Core Animation to:

  • Create custom animations

  • Add timing functions to graphics

  • Support key frame animation

  • Specify graphical layout constraints

  • Group multiple-layer changes into an atomic update

The OpenGL Framework Provides Tools for 2D and 3D Drawing

Use OpenGL for developing advanced three-dimensional (3D) graphics apps. OpenGL is specifically designed for apps such as games that need a rich, robust framework for visualizing shapes in two and three dimensions. Apple’s implementation of the OpenGL standard works closely with the hardware to provide high frame rates for full-screen game-style apps.

Use OpenGL to:

  • Create 2D and 3D graphics

  • Make more complex graphics such as data visualization, flight simulation, or video games

  • Use multiple threads to process graphics data

  • Access underlying graphics hardware

Understand the Differences and Similarities between OS X and iOS API

If you’re an iOS developer, you’ll find that Cocoa and Cocoa Touch apps are based on similar technologies. Their shared API makes it easier to migrate from Cocoa Touch. In fact, some frameworks are identical (or nearly identical), like Foundation and Core Data. However, other frameworks are distinct from their iOS counterparts. This is especially true of AppKit and UIKit. Therefore, when migrating an iOS app to OS X, you must replace a significant number of interface-related classes and code related to those classes.

For more information on differences and similarities between platforms, see “Migrating from Cocoa Touch” in Mac OS X Technology Overview.

Add Other Frameworks to Your Project as Needed

There are many more frameworks you can use in your app. When you decide that you need to use a framework that is not already included, add the framework to your project so that your app can link to it.

image: ../Art/Add_framework.png
To link the TrackMix.xcodeproj to another framework
  1. Open the TrackMix.xcodeproj project in Xcode (if it’s not already open).

  2. Click the TrackMix project in the project navigator to show the project editor.

  3. Specify TrackMix as the link target for your framework by clicking TrackMix in the Targets list.

  4. Click Build Phases at the top of the project editor.

  5. Open the Link Binary With Libraries section by clicking the disclosure triangle.

  6. Click the Add (+) button to add a framework.

  7. Select a framework from the list and click Add.

For a complete list of the frameworks, or to learn more about them, see Mac OS X Technology Overview.