Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge....

129
© 2016 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. Using modern best practices App Frameworks #WWDC16 Session 213 Improving Existing Apps Woody L., to the Knowledge

Transcript of Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge....

Page 1: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

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

Using modern best practices

App Frameworks #WWDC16

Session 213

Improving Existing Apps

Woody L., 🐳 to the Knowledge

Page 2: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Agenda

Reduce Technical DebtAsset CatalogsDependency InjectionLive Playgrounds

Page 3: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Cycle of Development

You down with ‘Dub-DC? Yeah, you know me.

Page 4: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Your bossLots of Requests

Page 5: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Your customersMore Requests

Page 6: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

//TODO: Write and clean up

Technical Debt

Customer’s Perspective Actuality

Page 7: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Duarte requesting hi-res photo

Page 8: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Foundation

Mail

AppKit

Messages

MobileSafari

AirPortUtilityAppKit

OpenCL

WebKit Dock

Mail

iCal

udf

bash

cups

CFzsh

xnu

AVFoundation

ActivityMonitor

MobileSafari

BlueToothSettings

AccessibilitySettings GameKit

QuickTime

AirPortAssistant

AppStore

AppStore zsh

GameKitAirPortAssistant Dock

AirPortSettings

MapKit

PreferencesApp

MobileMusicPlayer

MobileMailMediaStreamMediaPlayerMediaPlayerUIGameKitServices

New API

Page 9: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Source code compatibilitySwift 3

Page 10: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

New and Updated Platforms

Page 11: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

A Dev’s Run Loop

♽Technical Debt

New andUpdated APIs

Customer Roadmap

Platforms

Bug Fixes

Page 12: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

A Dev’s Run Loop

♽Technical Debt

New andUpdated APIs

Customer Roadmap

Platforms

Bug Fixes

Page 13: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

A Dev’s Run Loop

♽Technical Debt

New andUpdated APIs

Customer Roadmap

Platforms

Bug Fixes

Page 14: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

The Essentials

A very good place to start

Page 15: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Minimum Deployment of iOS 8• 95% of Devices

Earlier 5%iOS 8

11%

iOS 9 84%

As measured by the App Store on May 9, 2016

Page 16: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Latest update of previous releasePick a Deployment Target

Page 17: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Deprecated API

Page 18: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Deprecated API

Page 19: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

LLVM—Warning Policy, Xcode 7.3Treat Warnings as Errors

Page 20: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Swift Compiler—Warning Policy, Xcode 8Treat Warnings as Errors NEW

Page 21: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

As much a part of your user interface as the artworkAccessibility in Xcode

Page 22: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

As much a part of your user interface as the artworkAccessibility in Xcode

Page 23: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

// Programmatic Accessibility of UI Components

let button = UIButton()

button.accessibilityLabel = "Add Bookmark"

Page 24: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Locale-Aware APIs

Locale Obtain current region and format

DateFormatter Format and parse dates and times

NumberFormatter Format and parse numbers

Calendar and TimeZone Current calendar and associated operations

Dimension Represent specific units of measure

MeasurementFormatter Format and parse units of quantity

PersonNameComponents Names of people

Page 25: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Locale-Aware APIs

Locale Obtain current region and format

DateFormatter Format and parse dates and times

NumberFormatter Format and parse numbers

Calendar and TimeZone Current calendar and associated operations

Dimension Represent specific units of measure

MeasurementFormatter Format and parse units of quantity

PersonNameComponents Names of people

NEW

Page 26: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Add Peek, Pop, and Quick Actions

Page 27: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Checklist for developer preview seedsGetting Ready for Autumn 2016

Run the Swift Migrator

Does it work?• No? Is it Apple’s problem or is it your code?• Are you using APIs in a way we didn’t expect?• Unit tests pass?

Page 28: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

bugreport.apple.comFile Bug Reports

Page 29: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

bugreport.apple.comFile Bug Reports

Dev Forums EmailBanter

MobileMe?

Broken!

Page 30: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

BugReport.apple.com

Page 31: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Where Do Lonely Bug Reports Go?

Page 32: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

“La-La, Can’t Hear You”

Page 33: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

“Each bug report is as unique as a snowflake.”

Paul M., Apple Software Engineer

Page 34: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Prepare your codebaseGet Started Today

iOS 9.3 + Xcode 7 iOS 10 + Xcode 8

Update project settings Use the Swift Migrator

Fix warnings Provide bug reports

Replace deprecated API Incorporate new API

Localize

Accessibility

Page 35: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Asset Catalogs

Or, as some might write, Catalogues

Page 36: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Files with naming conventionsThe Old Way

Page 37: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Asset catalogThe Modern Way

Page 38: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Add a Catalog

Page 39: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Multiple Asset Catalogs

Page 40: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Multiple Asset Catalogs

Page 41: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Migrating Project Images

Page 42: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Migrating Project Images

Page 43: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Migrating Project Images

Page 44: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Migrating Project Images

Page 45: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Migration Completed

Page 46: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

// Loading Image Assets

// Old Way

if let logo = UIImage(contentsOfFile: Bundle.main().pathForResource("Logo", ofType: “png")) {

imageView.image = logo

}

// Modern Way

if let logo = UIImage(named: "List") {

imageView.image = logo

}

Old Way

Page 47: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

// Loading Image Assets

// Old Way

if let logo = UIImage(contentsOfFile: Bundle.main().pathForResource("Logo", ofType: “png")) {

imageView.image = logo

}

// Modern Way

if let logo = UIImage(named: "List") {

imageView.image = logo

}

Old Way

Page 48: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

// Loading Image Assets

// Old Way

if let logo = UIImage(contentsOfFile: Bundle.main().pathForResource("Logo", ofType: “png")) {

imageView.image = logo

}

// Modern Way

if let logo = UIImage(named: "List") {

imageView.image = logo

}

Old Way

Page 49: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

// Loading Image Assets

// Old Way

if let logo = UIImage(contentsOfFile: Bundle.main().pathForResource("Logo", ofType: “png")) {

imageView.image = logo

}

// Modern Way

if let logo = UIImage(named: "List") {

imageView.image = logo

}

Old Way

Page 50: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Multiple Representations of Assets

Page 51: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Multiple Representations of Assets

Page 52: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Multiple Representations of Assets

Page 53: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Multiple Representations of Assets

Page 54: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Multiple Representations of Assets

Page 55: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Multiple Representations of Assets

Page 56: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Multiple Representations of Assets

Page 57: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Multiple Representations of Assets

Page 58: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Multiple Representations of Assets

Page 59: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Asset Types

Individual Scales Single Vector

PNGs PDFs

Page 60: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Selecting the Scale Factor

Page 61: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

No 2x and 3x artworkMissing Scaled Asset Representations

Page 62: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

No 2x and 3x artworkMissing Scaled Asset Representations

Scaled up for Retina devices

Missing Retina artwork

Page 63: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Only 3x mediaMissing PNG Asset Representations

Scaled down for 1x and 2x displays

Missing 1x and 2x artwork

Page 64: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Asset Scaling and Memory

1x 3x9Kb 943Kb

Page 65: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Memory PressureM

emor

y U

tiliz

atio

n

Temporary Memory Spike

Start 3x Image Load Image Opened and Scaling to 2x Scaled, Original Deallocated

Page 66: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Memory PressureM

emor

y U

tiliz

atio

n

Temporary Memory Spike

Start 3x Image Load Image Opened and Scaling to 2x Scaled, Original Deallocated

Page 67: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Memory PressureM

emor

y U

tiliz

atio

n

Temporary Memory Spike

Start 3x Image Load Image Opened and Scaling to 2x Scaled, Original Deallocated

Page 68: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Automator

Page 69: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

-

Page 70: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Scalable to any sizeVector Assets

Page 71: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Scalable to any sizeVector Assets

Page 72: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Scaled and rasterized at build timeVector Assets

Page 73: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Scaled and rasterized at build timeVector Assets

Page 74: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Improving asset image qualityOverride Universal Vector Assets

Page 75: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Improving asset image qualityOverride Universal Vector Assets

Page 76: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Lossy and losslessImage Compression NEW

Page 77: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Challenge of rounded cornersCapped Images

Continue

Page 78: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Challenge of rounded cornersCapped Images

Continue

Page 79: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Challenge of rounded cornersCapped Images

Continue

Page 80: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Challenge of rounded cornersCapped Images

Continue

Page 81: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Challenge of rounded cornersCapped Images

Continue

Page 82: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Challenge of rounded cornersCapped Images

Continue

Page 83: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Interface Builder’s Attributes InspectorButton Background Image

Page 84: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Interface Builder’s Attributes InspectorButton Background Image

Page 85: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Interface Builder’s Attributes InspectorButton Background Image

Page 86: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Challenge of rounded cornersCapped Images

RoundedRectangle

Page 87: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Challenge of rounded cornersCapped Images

Page 88: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

// Stretchable Images

// Programmatic, Traditional Way:

if let image = UIImage(named: “RoundedRectangle")

let background = image.stretchableImage(withLeftCapWidth: 10, topCapHeight: 10) {

button.setBackgroundImage(background, for: [])

}

Page 89: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Asset Slicing

Page 90: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Asset Slicing

Page 91: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Don’t stretch these edges H H

HH

Page 92: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Don’t stretch these edges H H

HH

Page 93: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Repeat these pixels

Page 94: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Repeat these pixels

Page 95: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Preserving of rounded cornersCapped Images

Page 96: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Asset CatalogsSummary

Use Asset CatalogsVector images preserve image qualityScaled images should be provided for each asset representation (1x, 2x, 3x)Perform slicing within the asset catalog

Page 97: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Dependency Injection

Pay it forward

Page 98: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Methods relating to UITextFieldUITextFieldDelegate

UITextField UITextFieldDelegate

func textFieldShouldBeginEditing(_ textField:

UITextField) -> Bool

func textFieldDidBeginEditing(_ textField: UITextField)

Page 99: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Methods relating to WCSessionWCSessionDelegate

WCSession WCSessionDelegate

func session(_ session: WCSession,

activationDidCompleteWith activationState:

WCSessionActivationState, error: NSError?)

Page 100: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Everything elseApp Delegate

NS/UIApplication NS/ApplicationDelegate

Page 101: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Everything elseApp Delegate

NS/UIApplication NS/ApplicationDelegate

func applicationWillResignActive(_ application: UIApplication)

Page 102: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Everything elseApp Delegate

NS/UIApplication NS/ApplicationDelegate

func applicationWillResignActive(_ application: UIApplication)

var sqlite3DB: SQLite3Db?

Page 103: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Everything elseApp Delegate

NS/UIApplication NS/ApplicationDelegate

func applicationWillResignActive(_ application: UIApplication)

var sqlite3DB: SQLite3Db?

var sink = Kitchen(garbageDisposal: true)

Page 104: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Convenient, but strongly coupledAccessing the App Delegate

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

return (UIApplication.shared().delegate as? AppDelegate)?.content?.count ?? 0

}

Page 105: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Tight couplingReach-Back to the App Delegate

View Controller AMailboxes

View Controller BMessages

View Controller CDetail

Application Delegate[MyModel]

Page 106: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Pay it forwardDependency Injection

MailboxesVC[Mailbox]()

MessagesVC[Message]?

MessageVCMessage?

Application Delegate

Page 107: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Storyboard SeguesDependency Injection

override func prepare(for segue: UIStoryboardSegue, sender: AnyObject?) {

if let messagesVC = segue.destinationViewController as? MessagesViewController {

messagesVC.content = model

}

}

MailboxesVC var content = [MailBoxes]()

MessagesViewControllervar: [MyModel]?

Page 108: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

MailboxesVC var content = [MailBoxes]()

MessagesViewControllervar: [MyModel]?

Programatic presentationDependency Injection

@IBAction func showDetailVC(sender: AnyObject?) {

let detailVC = DetailVC()

let indexOfSelectedMessage = 0// ...

let message = messages[indexOfSelectedMessage]

detailVC.message = message

}

Continue

Page 109: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Coming back from Dependency InjectionReturning from the View Controller

Create and implement a Protocol• UIImagePickerControllerDelegate• MFMailComposeViewControllerDelegate• Mark the delegate property as weak to prevent memory leaks to prevent circular references

Pass a Closure to the Destination View ControllerPass Model Objects by ReferenceUnwind/Exit Segues, with prepareForSegue:

Page 110: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Flashback to 2015Previously at WWDC

Once upon a time, in a session room not that far away…

Page 111: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Modernizing existing apps with SwiftWWDC2015

Page 112: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Modernizing existing apps with SwiftWWDC2015

Playgrounds InteroperabilityModern UI

Page 113: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Live Playgrounds!

Better than !(Live Playgrounds)

Page 114: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

DemoTableViews in Live Playgrounds

The Needle? We like to move it, move it.

Page 115: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Live Playground supporting APIDemo Summary

Import the Playground Module

import PlaygroundSupport

Indefinite/Asynchronous Execution

PlaygroundPage.current.needsIndefiniteExecution = true

Assign a Live View

PlaygroundPage.current.liveView = customTableViewController.tableView

Page 116: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

TipsDemo Summary

Playground Sources and Resources• Files dragged to these folders are copied, not referenced• Methods, properties, and data types in the Sources folder must use the Public specifier

Page 117: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Caches folderDemo Summary

Temporary data that can be recreated if it’s missingThumbnailsDownloaded resourcesPurged when device under storage pressure

let fm = FileManager.default()

let cacheUrl = fm.urlsForDirectory(.cachesDirectory, inDomains: .userDomainMask).last

Page 118: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Powerful and performantURLSession

Out-of-process networkingDelegation and completion handlersSupported by tvOS, iOS, macOS, and watchOS platformsBacked by the expertise of our core networking engineers

NSURLSession: New Features and Best Practices Pacific Heights Thursday 10:00AM

Networking for the Modern Internet Pacific Heights Thursday 3:00PM

Page 119: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Must See

It’s time to play the music, it’s time to light the lights

Tv16

Page 120: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

// tvOS Conditional Compilation

#if os(tvOS)

backgroundImageView.adjustsImageWhenAncestorFocused = true

#endif

Page 121: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Human Interface GuidelinesAdopting Additional Platforms

Page 122: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Invoicing

Page 123: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Financial Charts

Page 124: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Adding Platforms

Read and use our Human Interface GuidelinesDesign to the platformPivot your data model

Page 125: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Summary

Modernizing your app is an on-going processRely on the frameworksStart today—No need to wait for Xcode 8Live Playgrounds allow for more experimentationArchitect your app with few inter-object dependenciesConsider bringing your model layer to our other platforms, with platform-specific UI

Page 126: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Related Sessions

What’s New in Cocoa Touch Presidio Tuesday 1:40PM

What’s New in tvOS Presidio Tuesday 3:00PM

What’s New in watchOS 3 Presidio Tuesday 5:00PM

What’s New in Swift Presidio Tuesday 9:00AM

Crafting Modern Cocoa Apps Pacific Heights Friday 5:00PM

Increase Usage of Your App with Proactive Suggestions Mission Friday 1:40PM

Page 127: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

Labs

Cocoa Touch Lab Frameworks Lab A Wednesday 3:00PM

Cocoa Lab Frameworks Lab D Thursday 2:00PM

Interface Builder and Auto Layout Lab Developer Tools Lab C Friday 9:00AM

UIKit and UIKit Animations Lab Frameworks Lab C Thursday 1:00PM

Swift Open Hours Developer Tools Lab A Daily

Page 128: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.

More Information

https://developer.apple.com/wwdc16/213

Page 129: Improving Existing Apps - Apple Inc.€¦ · Improving Existing Apps Woody L., ! to the Knowledge. Agenda Reduce Technical Debt Asset Catalogs Dependency Injection Live Playgrounds.