iOS App Programming Guide => Design Basic & Core Objects

来源:互联网 发布:武极天下神迹升级数据 编辑:程序博客网 时间:2024/04/28 22:19

iOS App Programming Guide

App Design Basics

Learning the Fundamental iOS Design Patterns and Techniques

The most important design patterns you must know are:

  • Model-View-Controller—This design pattern governs the overall structure of your app.
  • Delegation—This design pattern facilitates the transfer information and data from one object to another.
  • Target-action—This design pattern translates user interactions with buttons and controls into code that your app can execute.
  • Block objects—You use blocks to implement callbacks and asynchronous code.
  • Sandboxing—All iOS apps are placed in sandboxes to protect the system and other apps. The structure of the sandbox affects the placement of your app’s files and has implications for data backups and some app-related features.

Core App Objects

The Core Objects of Your App

UIApplication object

You use the UIApplication object essentially as is—that is, without subclassing. This controller object manages the app event loop and coordinates other high-level app behaviors. Your own custom app-level logic resides in your app delegate object, which works in tandem with this object.App delegate objectThe app delegate is a custom object created at app launch time, usually by theUIApplicationMain function. The primary job of this object is to handle state transitions within the app.Documents and data model objectsData model objects store your app’s content and are specific to your app.
Apps can also use document objects (custom subclasses of UIDocument) to manage some or all of their data model objects. Document objects are not required but offer a convenient way to group data that belongs in a single file or file package.View controller objectsView controller objects manage the presentation of your app’s content on screen. A view controller manages a single view and its collection of subviews. When presented, the view controller makes its views visible by installing them in the app’s window.

UIWindow object

A UIWindow object coordinates the presentation of one or more views on a screen. Most apps have only one window, which presents content on the main screen, but apps may have an additional window for content displayed on an external display.View, control, and layer objectsViews and controls provide the visual representation of your app’s content. Aview is an object that draws content in a designated rectangular area and responds to events within that area.Controls are a specialized type of view responsible for implementing familiar interface objects such as buttons, text fields, and toggle switches.
In addition to incorporating views and controls, apps can also incorporate Core Animation layers into their view and control hierarchies.Layer objects are actually data objects that represent visual content. Views use layer objects intensively behind the scenes to render their content. You can also add custom layer objects to your interface to implement complex animations and other types of sophisticated visual effects.

The Data Model

Data classes in the Foundation framework:

Data

Classes

Description

Strings and text

NSString (NSMutableString)

NSAttributedString (NSMutableAttributedString)

Strings in iOS are Unicode based. The string classes provide support for creating and manipulating strings in a variety of ways. The attributed string classes support stylized text and are used only in conjunction with Core Text.

Numbers

NSNumber

NSDecimalNumber

NSIndexPath

When you want to store numerical values in a collection, use number objects. TheNSNumber class can represent integer, floating-point values, Booleans, andchar types. TheNSIndexPath class stores a sequence of numbers and is often used to specify multi-layer selections in hierarchical lists.

Raw bytes

NSData (NSMutableData)

NSValue

For times when you need to store raw streams of bytes, use data objects. Data objects are also commonly used to store objects in an archived form. TheNSValue class is typically extended (usingcategories) and used to archive common data types such as points and rectangles.

Dates and times

NSDate

NSDateComponents

Use date objects to store timestamps, calendar dates, and other time-related information.

URLs

NSURL

In addition to their traditional use for referring to network resources, URLs in iOS are the preferred way to store paths to files. TheNSURL class even provides support for getting and setting file-related attributes.

Collections

NSArray (NSMutableArray)

NSDictionary (NSMutableDictionary)

NSIndexSet (NSMutableIndexSet)

NSOrderedSet (NSMutableOrderedSet)

NSSet (NSMutableSet)

Use collections to group related objects together in a single place. The Foundation framework provides several different types of collection classes

Other commonly used data types:

  • NSInteger/NSUInteger—Abstractions for scalar signed and unsigned integers that define the integer size based on the architecture.

  • NSRange—A structure used to define a contiguous portion of a series. For example, you can use ranges to define the selected characters in a string.

  • NSTimeInterval—The number of seconds (whole and partial) in a given time interval.

  • CGPoint—An x and y coordinate value that defines a location.

  • CGSize—Coordinate values that define a set of horizontal and vertical extents.

  • CGRect—Coordinate values that define a rectangular region.

You can also use Core Data(Core Data Programming Guide) or Document Objects(Document-Based App Programming Guide for iOS) when construct your data model

The User Interface

We can build an interface with UIKit Views(View Programming Guide for iOS) or OpenGL ES(OpenGL ES Programming Guide for iOS).

The App Bundle

A bundle(Bundle Programming Guide) is a directory in the file system that groups related resources together in one place. An iOS app bundle contains the app executable file and supporting resource files such as app icons, image files, and localized content.

A typical app bundle

File

Example

Description

App executable

MyApp

The executable file contains your app’s compiled code. The name of your app’s executable file is the same as your app name minus the.app extension.

This file is required.

The information property list file

Info.plist

The Info.plist file contains configuration data for the app. The system uses this data to determine how to interact with the app.

This file is required and must be called Info.plist. For more information, see“The Information Property List File.”

App icons

Icon.png

Icon@2x.png

Icon-Small.png

Icon-Small@2x.png

Your app icon is used to represent your app on the device’s Home screen. Other icons are used by the system in appropriate places. Icons with@2x in their filename are intended for devices with Retina displays.

An app icon is required. For information about specifying icon image files, see“App Icons.”

Launch images

Default.png

Default-Portrait.png

Default-Landscape.png

The system uses this file as a temporary background while your app is launching. It is removed as soon as your app is ready to display its user interface.

At least one launch image is required. For information about specifying launch images, see“App Launch (Default) Images.”

Storyboard files (or nib files)

MainBoard.storyboard

Storyboards contain the views and view controllers that the app presents on screen. Views in a storyboard are organized according to the view controller that presents them. Storyboards also identify the transitions (called segues) that take the user from one set of views to another.

The name of the main storyboard file is set by Xcode when you create your project. You can change the name by assigning a different value to theNSMainStoryboardFile key in theInfo.plist file.) Apps that usenib files instead of storyboards can replace theNSMainStoryboardFile key with theNSMainNibFile key and use that key to specify their main nib file.

The use of storyboards (or nib files) is optional but recommended.

Ad hoc distribution icon

iTunesArtwork

If you are distributing your app ad hoc, include a 512 x 512 pixel version of your app icon. This icon is normally provided by the App Store from the materials you submit to iTunes Connect. However, because apps distributed ad hoc do not go through the App Store, your icon must be present in your app bundle instead. iTunes uses this icon to represent your app. (The file you specify should be the same one you would have submitted to the App Store, if you were distributing your app that way.)

The filename of this icon must be iTunesArtwork and must not include a filename extension. This file is required for ad hoc distribution but is optional otherwise.

Settings bundle

Settings.bundle

If you want to expose custom app preferences through the Settings app, you must include a settings bundle. This bundle contains theproperty list data and other resource files that define your app preferences. The Settings app uses the information in this bundle to assemble the interface elements required by your app.

This bundle is optional. For more information about preferences and specifying a settings bundle, seePreferences and Settings Programming Guide.

Nonlocalized resource files

sun.png

mydata.plist

Nonlocalized resources include things like images, sound files, movies, and custom data files that your app uses. All of these files should be placed at the top level of your app bundle.

Subdirectories for localized resources

en.lproj

fr.lproj

es.lproj

Localized resources must be placed in language-specific project directories, the names for which consist of an ISO 639-1 language abbreviation plus the.lproj suffix. (For example, theen.lproj, fr.lproj, andes.lproj directories contain resources localized for English, French, and Spanish.)

An iOS app should be internationalized and have alanguage.lproj directory for each language it supports. In addition to providing localized versions of your app’s custom resources, you can also localize your app icon, launch images, and Settings icon by placing files with the same name in your language-specific project directories.

For more information, see “Localized Resource Files.”


0 0
原创粉丝点击