- Design pattern used by iOS:
- MVC
- Block objects ﹣ encapsulate code and local stack variables in a form that can be executed later. blocks often act as callbacks for async tasks. Supported by iOS 4 or later.
- Delegation - Instead of subclassing, you use the complex object as is and put any custom code for modifying the behavior of that object inside a separate object, which is referred to as the delegate object.
- Target-When the user interacts with a control in a predefined way (such as by touching a button), the control sends a message (the action) to an object you specify (the target). Upon receiving the action message, the target object can then respond in an appropriate manner.
- Managed memory model
Application life cycle
- The main function is located in that project’s
main.mfile. Every application you create will have a main function, which is the initial entry point for every iPhone application- This function performs two key tasks. First, it creates the application’s top-level autorelease pool used by the memory management reference counting system. Second, it calls the
UIApplicationMain function to create the application’s key objects, initialize those objects, and start the event-processing loop. The application does not return from this function until it quits.- The
UIApplicationMain function at the heart of your application’s main function takes four parameters and uses them to initialize the application. Although you should never have to change the default values passed into this function, it is worth explaining their purpose in terms of starting the application.- The
argcandargvparameters contain any launch-time arguments passed to the application from the system. These arguments are parsed by the UIKit infrastructure and can otherwise be ignored. - The third parameter identifies the name of the application’s principal class. This is the class responsible for running the application. Specifying
nilcauses UIKit to use theUIApplicationclass, which is recommended. - The fourth parameter identifies the class of the application delegate. The application delegate is responsible for managing the high-level interactions between the system and your custom code. Specifying
niltells UIKit that the application delegate object is located in the application’s main nib file (Application's main nib file is configured in info.plist).
In the main nib file, "MainWindow.xib" by default, specify delegate object. Usually name as {AppName}AppDelegate.
After app launched, function "applicationDidFinishLaunching" in AppDelegate will be invoked. Usually, viewController is initialized here.
iOS application layers: (from top down)
1. Cocoa touch layer - handle application launch/quit, touch event, etc. Made up of frameworks like UIKit, MapKit, GameKit etc.
2. Media layer - frameworks: MediaPlayer, AudioToolbox, etc.
3. Core Service layer - used for lower-level operation such as file access, networking, etc. Made up of frameworks Foundation, CoreFoundation, CoreData, etc.
4. Core OS layer - frameworks: System, Security, etc.
Core App Class
NSObject - the root class
UIApplication - the application object
UIWindow - window objects
VIew - Views
UIResponder - Responders
UIControl - Onscreen Controls (UIControl class inherits from UIView)
UIViewController - View Controllers
iOS application layers: (from top down)
1. Cocoa touch layer - handle application launch/quit, touch event, etc. Made up of frameworks like UIKit, MapKit, GameKit etc.
2. Media layer - frameworks: MediaPlayer, AudioToolbox, etc.
3. Core Service layer - used for lower-level operation such as file access, networking, etc. Made up of frameworks Foundation, CoreFoundation, CoreData, etc.
4. Core OS layer - frameworks: System, Security, etc.
Core App Class
NSObject - the root class
UIApplication - the application object
UIWindow - window objects
VIew - Views
UIResponder - Responders
UIControl - Onscreen Controls (UIControl class inherits from UIView)
UIViewController - View Controllers
沒有留言:
張貼留言