2. Overview of the iOS 7 Application
Development Architecture
These are confidential sessions - please refrain from streaming, blogging, or taking pictures
Session 7
Vu Tran Lam
IAD-2013
4. Creating iOS apps is fun and rewarding. If you're a new developer,
you might be wondering where to begin. This road map provides the
perfect starting point for iOS app development.
5. When you develop apps, you use the iOS software development kit
(SDK) and Xcode, Apple’s integrated development environment (IDE).
6. To make a great iOS app, you need to learn and do many things, but
the tools and iOS SDK make it easy to get a simple app running.
Let’s do the tutorial Your First iOS App.
7. Xcode provides tools to manage your entire development workflow-
from creating your app and designing your user interface, to testing,
optimizing, and shipping your app to the App Store.
8. Objective-C is an elegant object-oriented language that is used in all
iOS apps. You need to understand this language in order to use most
iOS application frameworks.
9. If you’ve learned enough about Objective-C to read and write basic
code, you can begin to think in terms of objects - OOP. To create an
iOS app, you need to know how to create, compare, query objects
and access objects in collections such as arrays.
10. iOS app consists of code that you write and frameworks provided by
Apple. A framework contains a library of methods that your app can use.
More than one app can access a framework library at the same time.
11. A design pattern solves a common software engineering problem.
Patterns are abstract designs, not code. When you adopt a design,
you adapt the general pattern to your specific needs.
12. Users expect iOS apps to be intuitive, interactive, and engaging. Think
about user experience as you design every aspect of your app, from
the features you choose to the way your app responds to a gesture.
13. Before you begin writing a line of code, you should make some
critical design decisions. Be as specific as possible about your app’s
purpose and features. Choose the kind of data model your app will
use. Decide on a user interface style for your app.
14. After completing your iOS App, if you want more and more iOS users
know and download your app, you must publish your app on the App
Store. To make a great app, you need to test it on actual devices, not
just in Simulator. To run an app on iOS-based devices, you need to
register your devices, create certificates that authorize developers to
sign an app, and create an app ID to identify the app.
15. While developing your apps, you’ll need easy access to detailed
technical information. Xcode makes that material available at your
fingertips while you're coding.
18. Model-View-Controller
• By default, iOS apps are organized around the Model-View-
Controller design pattern.
• The Model-View-Controller (MVC) design pattern assigns objects in
an application one of three roles: model, view, or controller. The
pattern defines not only the roles objects play in the application, it
defines the way objects communicate with each other.
• MVC is central to a good design for a Cocoa Touch application.
Many objects in these applications tend to be more reusable, and
their interfaces tend to be better defined.
• Applications having an MVC design are also more easily extensible
than other applications.
20. Assign objects in an application to one of three roles.
ViewModel
Controller
Model-View-Controller
21. Model objects encapsulate the data specific to an application and define
the logic and computation that manipulate and process that data, e.g: a
model object represent a character in game or a contact in address book.
Model View
Controller
Model-View-Controller
22. A view object is an object in an application that users can see. A view
object knows how to draw itself and can respond to user actions.
Model View
Controller
Model-View-Controller
23. A controller object acts as an intermediary between view and model
objects. In MVC, a controller object interprets user actions made in view
objects and communicates new or changed data to the model objects.
Model View
Controller
Model-View-Controller
34. ViewModel
action
target
The delegate is set via a protocol (i.e. it’s “blind” to class).
delegate
should did
will
Controller
outlet
update
update
Model-View-Controller
37. ViewModel
action
target
Controllers are almost always that data source (not Model!).
data
source
data
at
count
delegate
should did
will
Controller
outlet
update
update
Model-View-Controller
39. ViewModel
action
target
Can the Model talk directly to the Controller?
data
source
data
at
count
delegate
should did
will
Controller
outlet
update
update
?
Model-View-Controller
40. ViewModel
So what if the Model has information to update or something?
action
target
data
source
data
at
count
delegate
should did
will
Controller
outlet
update
update
?
Model-View-Controller
41. ViewModel
It uses a “radio station”-like broadcast mechanism
action
target
notification
data
source
data
at
count
delegate
should did
will
Controller
outlet
update
update
notify
Model-View-Controller
42. Controllers (or other Model) “tune in” to interesting stuff.
action
ViewModel
target
notification
data
source
data
at
count
delegate
should did
will
Controllernotify outlet
update
update
Model-View-Controller
44. Delegation
• Delegation is the design pattern which facilitates the transfer
information and data from one object to another. In delegation, an
object called the delegate acts on behalf of, and at the request of,
another object.
• A prime example of delegation can be seen in the case of the
UIApplication class. The UIApplication class, of which every iOS
iPhone application must have one instance, is responsible for the
control and operation of the application within the iOS environment.
• The Application Delegate is a custom object created at app launch
time, usually by the UIApplicationMain function.
• The primary job of Application Delegate is to handle state
transitions within the app. For example, this object is responsible for
launch-time initialization and handling transitions to and from the
45. Managing App State Changes
• The app launch cycle
• Responding to interruptions
• Moving to the background
• Returning to the foreground
• The main run loop
54. The Main Run Loop
The main run loop of your app is responsible for processing all user-
related events. The UIApplication object sets up the main run loop at
launch time and uses it to process events and handle updates to view-
based interfaces.
55. Target-Action
• Target-action is a design pattern in which an object holds the
information necessary to send a message to another object when an
event occurs.
• The stored information consists of two items of data: an action
selector, which identifies the method to be invoked, and a target,
which is the object to receive the message.
• The message sent when the event occurs is called an action
message.
56. • For example, when a user interacts with a slider (action), it
generates a UIControlEventValueChanged control event. You
could use this event to update a label’s text to the current value
of the slider. In this case, the sender is the slider, the control
event is Value Changed, the action is updating the label’s text,
and the target is the controller file containing the label as an
IBOutlet.
• Action methods must have a conventional signature as
- (IBAction)doSomething:(id)sender;!
• UIKit framework allows three different forms of action selector:
- (void)action;
- (void)action:(id)sender;
- (void)action:(id)sender forEvent:(UIEvent *)event;
Target-Action
57. • Target-action is primarily a feature of
controls in both the Cocoa Touch and
Cocoa frameworks.
• A control is a user-interface object such
as a button, slider, or switch that users
manipulate (by tapping, dragging, and so
on) to signal their intention to an app.
• A Cocoa Touch control stores both
action and target; most Cocoa controls
are paired with one or more cell objects
that store target and action.
Target-Action
58. Block Objects
• Block objects are a C-level syntactic and runtime feature that allow
you to compose function expressions that can be passed as
arguments, optionally stored, and used by multiple threads.
• Declaring a block
float (^aBlock)(const int*, int, float);
• Creating a block
int (^oneFrom)(int);
oneFrom = ^(int anInt) {
return anInt - 1;
};
• Using block
printf("%dn", oneFrom(10));
59. 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.
60. • Concept of View Controller
• Visual Interfaces
• View Controllers manage Views
• Taxonomy of View Controllers
• Using Storyboards to design User Interface
Overview of View Controllers
61. • View controllers are a vital link between an app’s data and its visual
appearance. Whenever an iOS app displays a user interface, the
displayed content is managed by a view controller or a group of
view controllers coordinating with each other.
• View controllers are traditional controller objects in the Model-View-
Controller (MVC) design pattern, but they also do much more. View
controllers provide many behaviors common to all iOS apps.
About View Controllers
63. • Each view controller organizes and controls a view
• View controllers are controller objects in the MVC pattern, but a
view controller also has specific tasks iOS expects it to perform.
• These tasks are defined by the UIViewController class that all view
controllers inherit from.
View Controllers Manage Views
64. • Each view controller organizes and controls a view
• View controllers are controller objects in the MVC pattern, but a
view controller also has specific tasks iOS expects it to perform.
• These tasks are defined by the UIViewController class that all view
controllers inherit from.
Taxonomy of View Controllers