Core iOS Application Architectural Patterns...Redistribution or public display not permitted without...

Preview:

Citation preview

© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

#WWDC14

Core iOS ApplicationArchitectural PatternsBuilding apps, it’s not just for breakfast anymore

Session 224 Bill Dudney UIKit Engineer

Frameworks

Introduction

Introduction

1 Common Patterns

Introduction

1 Common Patterns

2 Use Them in Your Code

Common PatternsUIKit and beyond

Common Patterns

Common Patterns

Target/Action

Target/Action

A consistent way to connect controls to custom logic

Making a Connection

Target/ActionSubtitle

Target/ActionSubtitle

Cancel Send

Target/ActionSubtitle

Cancel Send

Send Message

Target/ActionSubtitle

UIBarButtonItem

UIButton

Target/ActionControls

Control

target

action

Target/ActionControls

Control Object

Target/ActionGesture Recognizers

Gesture Recognizer Objectaction

target

Target/Action

Responder Chain

Responder Chain

Handle events without knowledge of which object will be used

Responder Chain

Initiator

Responder Chain

ResponderactionInitiator

Responder Chain

RespondernextResponder

ResponderactionInitiator

Responder Chain

RespondernextResponder

RespondernextResponder

ResponderactionInitiator

Responder ChainResponder

nextResponder

RespondernextResponder

RespondernextResponder

ResponderactionInitiator

Responder ChainMotion events

Responder ChainMotion events

Responder ChainMotion events

motionBegan:withEvent:motionEnded:withEvent:motionCancelled:withEvent:

Responder

nextResponder

Responder ChainAll applications

ViewView Controller

Window

Application AppDelegate

Responder Chain

Composite

CompositeView hierarchy

Manipulate a group of objects as a single object

CompositeView hierarchy

View

CompositeView hierarchy

View

View

CompositeView hierarchy

View

View

CompositeView hierarchy

View

View

View

View

CompositeView hierarchy

CompositeView hierarchy

View

View

CompositeResponder chain

View

View

CompositeUIDynamicBehavior

Dynamic Behavior

Dynamic Behavior

Composite

Delegation

Delegation

Customize behavior without subclassing

DelegationUIApplicationDelegate

UIApplication UIApplicationDelegate

Delegation

UIApplication UIApplicationDelegate

Delegation

UIApplication UIApplicationDelegate

AVAssetResourceLoader AVAssetResourceLoaderDelegate

CALayer CALayerDelegate

GKSession GKSessionDelegate

Delegation

Data Source

Data Source

Customize data retrieval without subclassing

Data SourceTable View

UITableView UITableViewDataSource

Data SourceIn UIKit

UITableView UITableViewDataSource

UICollectionView UICollectionViewDataSource

UIPageViewController UIPageViewControllerDataSource

UIPickerView UIPickerViewDataSource

subclassing

Data Source

Customize data retrieval without

subclassing

Data Source

Customize withoutbehavior

Data Source

Model-View-Controller

Model-View-Controller

Provide organizational structure to focus responsibilities

Model-View-Controller

Model

View Controller

Model-View-Controller

Model

View Controller

Model-View-Controller

Model

View Controller

Model-View-Controller

Controller

Model

View

Model-View-Controller

Applying PatternsYour code—made better

Sample App

Application Definition Statement

Allow people to share simple, short updates about what is happening in their lives

Application Definition Statement

Allow people to share simple, short updates about what is happening in their lives

Application Definition Statement

Allow people to share simple, short updates about what is happening in their lives

Application Definition Statement

Allow people to share simple, short updates about what is happening in their lives

Qwinkle

Qwinkle

Networked

Lists of data

Good performance

Add an entry

Add photos

Mark items

Edit posts

Application Definition Statement

Allow people to share simple, short updates about what is happening in their lives

Qwinkle

Networked

Lists of data

Good performance

Add an entry

Add photos

Mark items

Edit posts

Building the App

Model-View-ControllerA guide to conceptualize our app

Model

View Controller

Model-View-ControllerA guide to conceptualize our app

Model

View Controller

A user can specify an avatar

ModelApplication data

ModelApplication data

A user can specify an avatar

A user can add an entry

A user can follow a friend

ModelApplication data

Qwinker

Avatar

Qwink

Model-View-ControllerA guide to conceptualize our app

Model

View Controller

Scrolling

TableView

ViewNavBar

TableViewCellImageViewTextView

TableViewCellImageViewTextView

Button

Porchetta t-bone meatloaf bresaola, ball tip short loin pig jerky brisket tongue bacon shank salami. Sirloin landjaeger pastrami shoulder beef shank, corned beef tail strip steak.

Distillery non post-ironic occupy photo booth. Tousled church-key laborum, four loko pork belly Vinegar twee chia jean shorts commodo.

Turducken cow drumstick, turkey flank tenderloin short ribs venison leberkas. T-bone hamburger fatback drumstick bacon salami pork biltong leberkas short loin shankle doner tri-tip

Tattooed keytar veniam, try-hard vegan assumenda quinoa chillwave. Viral sed, accusamus 90's adipisicing gentrify iPhone ethical flexitarian.

Twee chia literally ugh swag. Flannel small batch fanny pack authentic Brooklyn cardigan letter-press

Composite

CompositeScrolling

TableView

ViewNavBar

TableViewCellImageViewTextView

TableViewCellImageViewTextView

Button

Porchetta t-bone meatloaf bresaola, ball tip short loin pig jerky brisket tongue bacon shank salami. Sirloin landjaeger pastrami shoulder beef shank, corned beef tail strip steak.

Distillery non post-ironic occupy photo booth. Tousled church-key laborum, four loko pork belly Vinegar twee chia jean shorts commodo.

Turducken cow drumstick, turkey flank tenderloin short ribs venison leberkas. T-bone hamburger fatback drumstick bacon salami pork biltong leberkas short loin shankle doner tri-tip

Tattooed keytar veniam, try-hard vegan assumenda quinoa chillwave. Viral sed, accusamus 90's adipisicing gentrify iPhone ethical flexitarian.

Twee chia literally ugh swag. Flannel small batch fanny pack authentic Brooklyn cardigan letter-press

Model-View-ControllerA guide to conceptualize our app

Model

View Controller

QwinkleData source

QwinkleData source

UITableView

QwinkleData source

UITableView QwinksViewController

QwinkleData source

UITableView

UITableViewDataSource

QwinksViewController

QwinkleTarget/Action

QwinksViewController

Model-View-ControllerNetworking

Table View Controller

NSURLSession

Porchetta t-bone meatloaf bresaola, ball tip short loin pig jerky brisket tongue bacon shank salami. Sirloin landjaeger pastrami shoulder beef shank, corned beef tail strip steak.

Distillery non post-ironic occupy photo booth. Tousled church-key laborum, four loko pork belly Vinegar twee chia jean shorts commodo.

Turducken cow drumstick, turkey flank tenderloin short ribs venison leberkas. T-bone hamburger fatback drumstick bacon salami pork biltong leberkas short loin shankle doner tri-tip

Tattooed keytar veniam, try-hard vegan assumenda quinoa chillwave. Viral sed, accusamus 90's adipisicing gentrify iPhone ethical flexitarian.

Twee chia literally ugh swag. Flannel small batch fanny pack authentic Brooklyn cardigan letter-press

Model-View-Controller

Porchetta t-bone meatloaf bresaola, ball tip short loin pig jerky brisket tongue bacon shank salami. Sirloin landjaeger pastrami shoulder beef shank, corned beef tail strip steak.

Distillery non post-ironic occupy photo booth. Tousled church-key laborum, four loko pork belly Vinegar twee chia jean shorts commodo.

Turducken cow drumstick, turkey flank tenderloin short ribs venison leberkas. T-bone hamburger fatback drumstick bacon salami pork biltong leberkas short loin shankle doner tri-tip

Tattooed keytar veniam, try-hard vegan assumenda quinoa chillwave. Viral sed, accusamus 90's adipisicing gentrify iPhone ethical flexitarian.

Twee chia literally ugh swag. Flannel small batch fanny pack authentic Brooklyn cardigan letter-press

Model-View-Controller

PublicTimelineViewController

Porchetta t-bone meatloaf bresaola, ball tip short loin pig jerky brisket tongue bacon shank salami. Sirloin landjaeger pastrami shoulder beef shank, corned beef tail strip steak.

Distillery non post-ironic occupy photo booth. Tousled church-key laborum, four loko pork belly Vinegar twee chia jean shorts commodo.

Turducken cow drumstick, turkey flank tenderloin short ribs venison leberkas. T-bone hamburger fatback drumstick bacon salami pork biltong leberkas short loin shankle doner tri-tip

Tattooed keytar veniam, try-hard vegan assumenda quinoa chillwave. Viral sed, accusamus 90's adipisicing gentrify iPhone ethical flexitarian.

Twee chia literally ugh swag. Flannel small batch fanny pack authentic Brooklyn cardigan letter-press

Model-View-Controller

Table View PublicTimelineViewController

Porchetta t-bone meatloaf bresaola, ball tip short loin pig jerky brisket tongue bacon shank salami. Sirloin landjaeger pastrami shoulder beef shank, corned beef tail strip steak.

Distillery non post-ironic occupy photo booth. Tousled church-key laborum, four loko pork belly Vinegar twee chia jean shorts commodo.

Turducken cow drumstick, turkey flank tenderloin short ribs venison leberkas. T-bone hamburger fatback drumstick bacon salami pork biltong leberkas short loin shankle doner tri-tip

Tattooed keytar veniam, try-hard vegan assumenda quinoa chillwave. Viral sed, accusamus 90's adipisicing gentrify iPhone ethical flexitarian.

Twee chia literally ugh swag. Flannel small batch fanny pack authentic Brooklyn cardigan letter-press

Model-View-Controller

Qwinker

Table View PublicTimelineViewController

Porchetta t-bone meatloaf bresaola, ball tip short loin pig jerky brisket tongue bacon shank salami. Sirloin landjaeger pastrami shoulder beef shank, corned beef tail strip steak.

Distillery non post-ironic occupy photo booth. Tousled church-key laborum, four loko pork belly Vinegar twee chia jean shorts commodo.

Turducken cow drumstick, turkey flank tenderloin short ribs venison leberkas. T-bone hamburger fatback drumstick bacon salami pork biltong leberkas short loin shankle doner tri-tip

Tattooed keytar veniam, try-hard vegan assumenda quinoa chillwave. Viral sed, accusamus 90's adipisicing gentrify iPhone ethical flexitarian.

Twee chia literally ugh swag. Flannel small batch fanny pack authentic Brooklyn cardigan letter-press

Model-View-Controller

Qwink

Entry View Qwink Entry View Controller

Gluten-free nesciunt swag kale chips assumenda, sed Reprehenderit bitters cillum excepteur. Hoodie trust fund pug ennui, lo-fi food truck est consectetur direct trade qui master cleanse biodiesel sint.

DoneCancel

QwinkleTarget/Action

PublicTimelineViewController

PublicTimelineViewController

Adding an EntryTarget/Action

Gluten-free nesciunt swag kale chips assumenda, sed Reprehenderit bitters cillum excepteur. Hoodie trust fund pug ennui, lo-fi food truck est consectetur direct trade qui master cleanse biodiesel sint.

DoneCancel

QwinkEntryViewController

Adding an EntryTarget/Action

Gluten-free nesciunt swag kale chips assumenda, sed Reprehenderit bitters cillum excepteur. Hoodie trust fund pug ennui, lo-fi food truck est consectetur direct trade qui master cleanse biodiesel sint.

DoneCancel

Gluten-free nesciunt swag kale chips assumenda, sed Reprehenderit bitters cillum excepteur. Hoodie trust fund pug ennui, lo-fi food truck est consectetur direct trade qui master cleanse biodiesel sint.

DoneCancel

Model-View-ControllerNetworking

Qwink Entry View Controller

Gluten-free nesciunt swag kale chips assumenda, sed Reprehenderit bitters cillum excepteur. Hoodie trust fund pug ennui, lo-fi food truck est consectetur direct trade qui master cleanse biodiesel sint.

DoneCancel

Model-View-ControllerNetworking

Qwink Entry View Controller

NSURLSession

QwinkleApplication level features

UIApplication

QwinkleApplication level features

QWKAppDelegateUIApplication

QwinkleApplication level features

QWKAppDelegateUIApplication

State Restoration

QwinkleApplication level features

QWKAppDelegateUIApplication

State Restoration

Background Downloading

Change Happens

Private Qwinks

Pork belly sausage capicola porchetta bresaola. Corned beef turkey boudin, ribeye

shankle tongue pig cow short ribs frankfurter pork chop landjaeger.

Brooklyn readymade dreamcatcher, mumblecore roof party actually normcore

plaid 90's quinoa kogi scenester.

Qwinks PQ

Pork belly sausage capicola porchetta bresaola. Corned beef turkey boudin, ribeye

shankle tongue pig cow short ribs frankfurter pork chop landjaeger.

Requirements Change

Pork belly sausage capicola porchetta bresaola. Corned beef turkey boudin, ribeye

shankle tongue pig cow short ribs frankfurter pork chop landjaeger.

Requirements Change

Requirements Change

Pork belly sausage capicola porchetta bresaola. Corned beef turkey boudin, ribeye

shankle tongue pig cow short ribs frankfurter pork chop landjaeger.

Requirements Change

Table View Controller

NSURLSession

Pork belly sausage capicola porchetta bresaola. Corned beef turkey boudin, ribeye

shankle tongue pig cow short ribs frankfurter pork chop landjaeger.

Requirements Change

Table View Controller

NSURLSession

Pork belly sausage capicola porchetta bresaola. Corned beef turkey boudin, ribeye

shankle tongue pig cow short ribs frankfurter pork chop landjaeger.

Pork belly sausage capicola porchetta bresaola. Corned beef turkey boudin, ribeye

shankle tongue pig cow short ribs frankfurter pork chop landjaeger.

Copy and Paste

PublicTimelineViewController

NSURLSession

PrivateMessageViewController

NSURLSession

Pork belly sausage capicola porchetta bresaola. Corned beef turkey boudin, ribeye

shankle tongue pig cow short ribs frankfurter pork chop landjaeger.

Copy and Paste

PublicTimelineViewController

NSURLSession

PrivateMessageViewController

NSURLSession

Download Service

Refactor

PublicTimelineViewController

PrivateMessageViewController

NSURLSession

Pork belly sausage capicola porchetta bresaola. Corned beef turkey boudin, ribeye

shankle tongue pig cow short ribs frankfurter pork chop landjaeger.

Refactor

PublicTimelineViewController

Download Service

Refactor

PublicTimelineViewController

Download Service

Refactor

PublicTimelineViewControllerdownload

Download Service

Refactor

PublicTimelineViewControllerdownload

response

Refactor

Download ServicePublicTimelineViewController

Refactor

DownloadServiceDelegate

Download ServicePublicTimelineViewController

Refactor

DownloadServiceDelegate

Download ServicePublicTimelineViewController

Refactor

DownloadServiceDelegate

Download ServicePublicTimelineViewController PrivateMessageViewController

DownloadServiceDelegate

Download Service

Demo

Summary

Summary

Summary

More Information

Jake Behrens Grand Pooh-Bah Of Groovy behrens@apple.com

Apple Developer Forums http://devforums.apple.com

• Advanced iOS Application Architecture and Patterns Presidio Thursday 2:00PM

• What’s New in Foundation Networking WWDC 2013

• API Design for Cocoa and Cocoa Touch WWDC 2010

Related Sessions

Recommended