Survey the Major Frameworks概述主要框架

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.

在应用程序开发中,OS X提供了很多框架可供使用。想使用一个框架,把它添加到你的project-项目中,那样应用程序就可以链接到它。 绝大多数应用程序都链接到Foundation , AppKit, Core Graphics 框架。 取决于你选择的何种模板,其它框架也有可能被包含。 你始终都可以往你的项目添加额外的框架,如果使用的框架核心集(core set)不符合你的需求。

一、To look at the frameworks included in TrackMix.xcodeproj
  查看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.

    在Xcode里打开TrackMix.xcodeproj项目。你应该已经Your First Mac App教程里创建了该项目。

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

    在项目导航(project navigator)点击展开按钮,打开框架(Frameworks)文件夹。

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

    继续点击展开按钮打开其它框架(other frameworks)文件夹。

    You should see AppKit.frameworkCoreData.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.

    你应该能看到 AppKit.frameworkCoreData.framework, 和 Foundation.framework. 尽管你在该项目没有使用Core Data, 这3个框架都始终被作为Cocoa 框架伞(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.

每个框架都跟OS X 系统的一个层相关联。 每层都建立在它的下一层基础之上。 任何时候请尽可能的使用高层框架(higher-level frameworks),而不是低层框架(lower-level frameworks)。 高层框架为低层结构提供了面向对象的抽象(object-oriented abstractions)。 这些抽象往往能减少你必须编写的代码总量。

image: ../Art/frameworks_layer.png

OS X Apps Are Based on the Foundation and AppKit Frameworks

OS X 应用程序都是基于 Foundation 和 AppKit 框架

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

当你开始编程,你主要使用Foundation 和 AppKit 框架,因为它们覆盖了大多数应用程序开发的需求。

The Foundation Framework Provides Basic System Services for All Apps

Foundation 框架为所有应用程序提供了各种基本系统服务

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.

你的所有应用程序,包括 AppKit 和其它矿机都是建立在Foundation框架基础设施的基础上的。 Foundation框架提供了很多原始对象类和数据类型,这使它成为所有应用开发的基础。 它同时也建立了各种约定(conventions)---为各种任务,比如释放(deallocation),这些约定让你的代码更加一致并可重复使用。

Use Foundation to:

Foundation框架可用来:

  • 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

     自动检测IP网络上的各种设备

  • Manipulate URL streams

     操作URL流

  • Execute code asynchronously

     异步执行代码

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

AppKit框架提供了各种类,用来创建一个图形化,事件驱动的用户界面

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.

所有Mac 应用程序都基于AppKit框架。 没有这个框架,你无法承载一个应用程序。 AppKit 提供了应用程序显示到屏幕,处理事件 和 创建通用用户界面元素的基础设施。 AppKit 通过管理显示在屏幕上的各种内容,把它们组织成一个复杂的应用程序。

Use AppKit to:

AppKit 可用来:

  • 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 callupdateUserInterface. In fact, you used AppKit to create your entire interface with the NSTextField and NSSliderclasses.

Your First Mac App 教程里,你使用了AppKit框架。 你实现了 NSApplicationDelegate 协议,用来调用 updateUserInterface方法。 实际上,就是用了 AppKit 框架里的NSTextField 和 NSSlider 类 创建了整个用户界面。

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.

Core Data, Core Graphics, Core Animation, 和 OpenGL框架都是先进技术。 尽管这些框架在应用开发中都很重要,但是它们需要你花事件去学习和掌握。

The Core Data Framework Manages the Data Model of an App

Core Data 框架 管理一个应用程序的数据模型

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.

Core Data 提供了面向图形管理系统。 用Core Data, 你可以创建各种模型对象,它们被称为管理对象。 你管理那些对象的关系,并通过框架改变其中的数据。 Core Data 利用 内置的 SQLite 技术来有效存储和管理数据。

Use Core Data to:

Core Data 可用来:

  • Save and retrieve objects from storage

     从存储位置(storage)保存和检索对象

  • Support basic undo/redo

     支持基本的取消/重做

  • Validate property values automatically

     自动验证特性值

  • Filter, group, and organize data in memory

     过滤,分组,以及组织内存中的数据

  • Manage results in a table view with NSFetchedResultsController

     用NSFetchedResultsController 管理 一个 table view里的结果

  • Support document-based apps

     支持基于文档的各种应用

The Core Graphics Framework Helps You Create Graphics

Core 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.

高质量图像在所有OS X 应用程序里都是很重要的。 在OS  X里创建各种图像的最简单有效方法是使用预渲染图片(prerendered images)和 AppKit框架的标准视图和控制,让OS X绘制。 AppKit 也提供了用来自定义画图的各种类---包括路径,颜色,设计模式,渐变,图案,文字 以及转换。 无论何时请尽可能的使用一个高层次框架--AppKit 代替 一个低层次框架--Core Graphics。

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.

当你想编写绘图代码用来在iOS 和 OS X之间直接共享时,使用Core Graphics. Core Graphics 框架--即Quartz---在两个平台上几乎一样。

Use Core Graphics to:

Core Graphics 可用来:

  • 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

Core Animation 让你制作高级动画和视觉效果

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.

AppKit 提供了建立在Core 动画技术顶端的动画。 如果你需要AppKit框架能力以上的先进动画,你可以直接使用Core Animation。 Core Animation 接口被包含在Quartz Core 框架里面。 用Core Animation, 你创建一个层对象们的层次结构,在该结构你可以进行操作,旋转,缩放和转换等等。 通过使用Core Animation 中 熟悉的 viewlike 抽象,你可以创建动态用户界面,而不需要使用低层次图像APIs,比如OpenGL。

Use Core Animation to:

Core Animation 可用于:

  • 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

OpenGL 框架提供了2D 和 3D 绘图的工具

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.

用OpenGL 开发先进的3D 图形应用。 OpenGL 是特别为像游戏之类的应用设计的,这些应用需要为可视化2D和3D图形提供一个丰富而健壮的框架。Apple公司的OpenGL标准工具跟硬件一起紧密工作,为全屏游戏应用提供高帧速率。

Use OpenGL to:

OpenGL 框架可用于:

  • Create 2D and 3D graphics

    创建 2D 和 3D 图形 

  • 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

理解OS X 和 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.

如果你是一个iOS开发者,你将发现Cocoa 和 Cocoa Touch 应用程序都基于类似技术。 它们共享API,使得从Cocoa Touch过渡到Cocoa变得简单。 事实上,有些框架完全一样(或几乎一样), 比如 Foundation 和 Core Data。然而,iOS的其他框架是不同的。这点对于Appkit 和 UIKit 框架尤其正确。因此,当你把一个iOS应用转为OS X应用时,你必须把显著数量的界面相关类 和相应的代码替换为那些类。

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

想要了解更多关于平台之间区别和相同点的信息,参见 Mac OS X Technology 里的 “Migrating from Cocoa Touch”。

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
  让TrackMix.xcodeproj 链接到另一个框架
  1. Open the TrackMix.xcodeproj project in Xcode (if it’s not already open).

     在Xcode 里打开TrackMix.xcodeproj项目

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

     点击项目导航里的TrackMix project,显示项目编辑器。

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

     在Targets列表里点击TrackMix,指定TrackMix成为链接目标。

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

     在project editor顶部点击Build Phases

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

     点击展开三角形,打开Link Binary With Libraries 项。

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

    点击“+”号添加一个框架。 

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

     从列表选择一个框架,点击“Add”。

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


 
原文地址:https://www.cnblogs.com/patientAndPersist/p/3134509.html