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.
iOS provides many frameworks that you can use in app development. To use a framework, add it to your project so your app can link to it. Most apps link to the Foundation, UIKit, 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 requirements.
![bullet](https://i-blog.csdnimg.cn/blog_migrate/ef61b107e9dab1f156012d60c1dcd6ee.png)
-
Open the
HelloWorld.xcodeproj
project in Xcode (if it’s not already open). You created this project earlier in theYour First iOS App tutorial. -
Open the Frameworks folder in the project navigator by clicking the disclosure triangle next to it.
You should see
UIKit.framework
,Foundation.framework
, andCoreGraphics.framework
. -
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 belongs to a layer of the iOS 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.
iOS Apps Are Based on the Foundation and UIKit Frameworks
When you begin programming, you mainly use the Foundation and UIKit 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 UIKit and other frameworks, are built on the Foundation framework infrastructure. The Foundation framework provides Objective-C wrappers for many of the features in the Core Foundation framework (which is C-based).
Use Foundation to:
-
Create and manage collections such as arrays and dictionaries.
-
Access images and other resources stored in your app.
-
Create and manage strings.
-
Post and observe notifications.
-
Create date and time objects.
-
Automatically discover devices on IP networks.
-
Manipulate URL streams.
-
Perform code asynchronously.
You already used the Foundation framework in Your First iOS App. For example, you used an instance of the NSString
class to store the user’s input in userName
. You also used the Foundation instance method initWithFormat:
to create the greeting string.
The UIKit Framework Provides Classes to Create a Touch-Based User Interface
All iOS apps are based on UIKit—you can’t ship an app without this framework. UIKit provides the infrastructure for drawing to the screen, handling events, and creating common user-interface elements. UIKit also organizes a complex app by managing the content that is displayed onscreen.
Use UIKit to:
-
Construct and manage your user interface.
-
Handle touch and motion-based events.
-
Present text and web content.
-
Optimize your app for multitasking.
-
Create custom user-interface elements.
In Your First iOS App Tutorial, you used UIKit. When you examined how an app starts up, you saw that theUIApplicationMain
function creates an instance of the UIApplication
class, which handles incoming user events. You implemented the UITextFieldDelegate
protocol in order to dismiss the keyboard when the user taps the Done key. In fact, you used UIKit to create your entire interface with the UITextField
, UILabel
, and UIButton
classes.
Other Important Frameworks You Should Know About
The Core Data, Core Graphics, Core Animation, and OpenGL ES 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 applications.
The Core Graphics Framework Helps You Create Graphics
High-quality graphics are an important part of all iOS applications. The simplest and most efficient way to create graphics in iOS is to use prerendered images with the standard views and controls of the UIKit framework and let iOS do the drawing. When you need to create complex graphics, Core Graphics provides a low-level graphics library to help you. Core Graphics, also known as Quartz, handles native 2D vector- and image-based rendering.
Use Core Graphics to:
-
Make path-based drawings.
-
Use anti-aliased rendering.
-
Add gradients, images, and colors.
-
Use coordinate-space transformations.
-
Create, display, and parse PDF documents.
Core Animation Allows You to Make Advanced Animations and Visual Effects
UIKit provides animations that are built on top of the Core Animation technology. If you need advanced animations beyond the capabilities of UIKit, 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 view-like abstraction, you can create dynamic user interfaces without having to use low-level graphics APIs like OpenGL ES.
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 ES Framework Provides Tools for 2D and 3D Drawing
OpenGL ES supports basic 2D and 3D drawing. Apple’s implementation of the OpenGL ES standard works closely with the device hardware to provide high frame rates for full-screen game-style applications.
Use OpenGL ES to:
-
Create 2D and 3D graphics.
-
Make more complex graphics such as data visualization, flight simulation, or video games.
-
Access underlying graphics hardware.
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 your app can link to it.
![bullet](https://i-blog.csdnimg.cn/blog_migrate/ef61b107e9dab1f156012d60c1dcd6ee.png)
-
Open the
HelloWorld.xcodeproj
project in Xcode (if it’s not already open). -
Click the HelloWorld project in the project navigator to show the project editor.
-
Specify HelloWorld as the target to which you want to add a framework by clicking HelloWorld in the Targets list.
-
Click Build Phases at the top of the project editor.
-
Open the Link Binary With Libraries section by clicking the disclosure triangle.
-
Click the Add (+) button to add a framework.
-
Select a framework from the list and click Add.
For a complete list of the frameworks, or to learn more about them, see the iOS Technology Overview.