Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools...

196
© 2016 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer Maxwell Swadling Playgrounds Engineer Jonathan Penn Playgrounds Engineer Izzy Fraimow Playgrounds Engineer

Transcript of Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools...

Page 1: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

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

Exploring with Swift on iPad

Developer Tools #WWDC16

Session 408

Introducing Swift Playgrounds

Matt Patenaude Playgrounds EngineerMaxwell Swadling Playgrounds EngineerJonathan Penn Playgrounds EngineerIzzy Fraimow Playgrounds Engineer

Page 2: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 3: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 4: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 5: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 6: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 7: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 8: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 9: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 10: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

1024 x 768

Page 11: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

1024 x 768

Page 12: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 13: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 14: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Using Swift Playgrounds

Page 15: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Using Swift PlaygroundsAuthoring for Swift Playgrounds

Page 16: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Using Swift PlaygroundsAuthoring for Swift PlaygroundsGrowing and Exploring

Page 17: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Using Swift Playgrounds

Maxwell SwadlingPlaygrounds Engineer

Page 18: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 19: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 20: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

PlaygroundMarkup

Page 21: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 22: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Source Code

Page 23: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 24: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

CodeCompletion

Page 25: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 26: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Undo/Redo

Page 27: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 28: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Shortcuts

Page 29: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 30: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Live View

Page 31: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 32: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Run Button

Page 33: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 34: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Documents

Page 35: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 36: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Table of Contents

Page 37: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 38: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

PageNavigation

Page 39: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 40: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Library

Page 41: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 42: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Tools Menu

Page 43: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 44: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 45: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Snippets

Page 46: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 47: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Images

Page 48: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 49: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Files

Page 50: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 51: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 52: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

DemoUsing Swift Playgrounds

Page 53: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Authoring for Swift Playgrounds

Jonathan PennPlaygrounds Engineer

Page 54: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 55: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 56: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 57: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Chapters / Pages

Introduction

Issuing Commands

Chapter: Commands

Introduction

Composing a New Behavior

Chapter: Functions

Page 58: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Chapters / Pages

Introduction

Issuing Commands

Chapter: Commands

Introduction

Composing a New Behavior

Chapter: Functions

Page 59: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Cutscenes

Page 60: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Cutscenes

Page 61: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Glossary

Page 62: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Glossary

Page 63: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Glossary

Page 64: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Editable Regions

Page 65: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Editable Regions

func /*#-editable-code*/ <#funcName#> /*#-end-editable-code*/() {

//#-editable-code Add commands to your function

//#-end-editable-code

}

//#-editable-code Tap to enter code

//#-end-editable-code

Page 66: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Hidden Code

Page 67: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Hidden Code

//#-hidden-code

yourSetupFunction()

//#-end-hidden-code

Page 68: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Configurable Code Completion

Page 69: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Configurable Code Completion

//#-code-completion(everything, hide)

//#-code-completion(currentmodule, show)

//#-code-completion(identifier, show, moveForward(), turnLeft())

Page 70: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

“Always-On” Live View

Page 71: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

“Always-On” Live View

Page 72: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Hints

Page 73: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Hints

Page 74: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Assessment

Page 75: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Assessment

Page 76: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Assessment

Page 77: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Assessment

Page 78: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

// Key/Value Store

import PlaygroundSupport

let store = PlaygroundPage.current.keyValueStore

store["Greeting"] = .string("Hello, WWDC!")

if case let .string(greeting)? = store["Greeting"] {

print(greeting) // "Hello, WWDC!"

}

Page 79: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Resettable

Page 80: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Resettable

Page 81: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Resettable

Page 82: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Resettable

Page 83: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Resettable

Page 84: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Resettable

Page 85: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Documented

apple.com

Page 86: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 87: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

1024 x 768

Page 88: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

DemoAuthoring for Swift Playgrounds

Page 89: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 90: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

MyFirst.playgroundbook

Page 91: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 92: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Contents

Chapter1.playgroundchapterPages

Chapters

Introduction.playgroundpage

HowDoesItWork.playgroundpage

Manifest.plistContents.swiftLiveView.swift

ResourcesSources

Page 93: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Contents

Pages

Chapters

Manifest.plistContents.swiftLiveView.swift

ResourcesSources

Chapter1.playgroundchapter

Introduction.playgroundpage

HowDoesItWork.playgroundpage

Page 94: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Contents

Pages

Chapters

Manifest.plistContents.swiftLiveView.swift

ResourcesSources

Chapter1.playgroundchapter

Introduction.playgroundpage

HowDoesItWork.playgroundpage

Page 95: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Contents

Pages

Chapters

Manifest.plistContents.swiftLiveView.swift

ResourcesSources

Chapter1.playgroundchapter

Introduction.playgroundpage

HowDoesItWork.playgroundpage

Page 96: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Contents

Pages

Chapters

Manifest.plistContents.swiftLiveView.swift

ResourcesSources

Chapter1.playgroundchapter

Introduction.playgroundpage

HowDoesItWork.playgroundpage

Page 97: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Contents

Pages

Chapters

Manifest.plistContents.swiftLiveView.swift

ResourcesSources

Chapter1.playgroundchapter

Introduction.playgroundpage

HowDoesItWork.playgroundpage

Page 98: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Contents

Pages

Chapters

Manifest.plistContents.swiftLiveView.swift

ResourcesSources

Chapter1.playgroundchapter

Introduction.playgroundpage

HowDoesItWork.playgroundpage

Page 99: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Contents

Pages

Chapters

Manifest.plistContents.swiftLiveView.swift

ResourcesSources

Chapter1.playgroundchapter

Introduction.playgroundpage

HowDoesItWork.playgroundpage

Page 100: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Contents

Pages

Chapters

Manifest.plistContents.swiftLiveView.swift

ResourcesSources

Chapter1.playgroundchapter

Introduction.playgroundpage

HowDoesItWork.playgroundpage

Page 101: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Key Type Value

Root Dictionary

Name String Introduction

LiveViewMode String VisibleByDefault

PosterReference String LiveViewPoster.png

LiveViewEdgeToEdge Boolean YES

PlaygroundLoggingMode String Off

Page Manifest

Page 102: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 103: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Name = “Introduction”

Page 104: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 105: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

LiveViewMode = “VisibleByDefault”

Page 106: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 107: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

PosterReference = “LiveViewPoster.png”

Page 108: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 109: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 110: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

LiveViewEdgeToEdge = YES

Page 111: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 112: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

LiveViewEdgeToEdge = NO

Page 113: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 114: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

PlaygroundLoggingMode = “Off”

Page 115: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Contents

Pages

Chapters

Manifest.plistContents.swiftLiveView.swift

ResourcesSources

Chapter1.playgroundchapter

Introduction.playgroundpage

HowDoesItWork.playgroundpage

Page 116: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Contents

Pages

Chapters

Manifest.plistContents.swiftLiveView.swift

ResourcesSources

Chapter1.playgroundchapter

Introduction.playgroundpage

HowDoesItWork.playgroundpage

Page 117: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 118: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Contents.swift

Page 119: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

// Contents.swift

/*:

Instructions about the page...

*/

//#-hidden-code

import PlaygroundSupport

func say(_ message: String) {

let page = PlaygroundPage.current

if let proxy = page.liveView as? PlaygroundRemoteLiveViewProxy {

proxy.send(.string(message))

}

}

//#-end-hidden-code

say(/*#-editable-code*/"<#Knock, knock!#>"/*#-end-editable-code*/)

Page 120: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

// Contents.swift

/*:

Instructions about the page...

*/

//#-hidden-code

import PlaygroundSupport

func say(_ message: String) {

let page = PlaygroundPage.current

if let proxy = page.liveView as? PlaygroundRemoteLiveViewProxy {

proxy.send(.string(message))

}

}

//#-end-hidden-code

say(/*#-editable-code*/"<#Knock, knock!#>"/*#-end-editable-code*/)

Page 121: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

// Contents.swift

/*:

Instructions about the page...

*/

//#-hidden-code

import PlaygroundSupport

func say(_ message: String) {

let page = PlaygroundPage.current

if let proxy = page.liveView as? PlaygroundRemoteLiveViewProxy {

proxy.send(.string(message))

}

}

//#-end-hidden-code

say(/*#-editable-code*/"<#Knock, knock!#>"/*#-end-editable-code*/)

Page 122: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

// Contents.swift

/*:

Instructions about the page...

*/

//#-hidden-code

import PlaygroundSupport

func say(_ message: String) {

let page = PlaygroundPage.current

if let proxy = page.liveView as? PlaygroundRemoteLiveViewProxy {

proxy.send(.string(message))

}

}

//#-end-hidden-code

say(/*#-editable-code*/"<#Knock, knock!#>"/*#-end-editable-code*/)

Page 123: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

// Contents.swift

/*:

Instructions about the page...

*/

//#-hidden-code

import PlaygroundSupport

func say(_ message: String) {

let page = PlaygroundPage.current

if let proxy = page.liveView as? PlaygroundRemoteLiveViewProxy {

proxy.send(.string(message))

}

}

//#-end-hidden-code

say(/*#-editable-code*/"<#Knock, knock!#>"/*#-end-editable-code*/)

Page 124: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

// Contents.swift

/*:

Instructions about the page...

*/

//#-hidden-code

import PlaygroundSupport

func say(_ message: String) {

let page = PlaygroundPage.current

if let proxy = page.liveView as? PlaygroundRemoteLiveViewProxy {

proxy.send(.string(message))

}

}

//#-end-hidden-code

say(/*#-editable-code*/"<#Knock, knock!#>"/*#-end-editable-code*/)

Page 125: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

// Contents.swift

/*:

Instructions about the page...

*/

//#-hidden-code

import PlaygroundSupport

func say(_ message: String) {

let page = PlaygroundPage.current

if let proxy = page.liveView as? PlaygroundRemoteLiveViewProxy {

proxy.send(.string(message))

}

}

//#-end-hidden-code

say(/*#-editable-code*/"<#Knock, knock!#>"/*#-end-editable-code*/)

Page 126: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 127: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Contents

Pages

Chapters

Manifest.plistContents.swiftLiveView.swift

ResourcesSources

Chapter1.playgroundchapter

Introduction.playgroundpage

HowDoesItWork.playgroundpage

Page 128: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

// LiveView.swift

import PlaygroundSupport

let page = PlaygroundPage.current

page.liveView = FaceViewController()

Page 129: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

// LiveView.swift

import PlaygroundSupport

let page = PlaygroundPage.current

page.liveView = FaceViewController()

Page 130: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

// LiveView.swift

import PlaygroundSupport

let page = PlaygroundPage.current

page.liveView = FaceViewController()

Page 131: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

// LiveView.swift

import PlaygroundSupport

let page = PlaygroundPage.current

page.liveView = FaceViewController()

Page 132: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Contents

ResourcesSources

Pages

Chapters

Manifest.plistContents.swiftLiveView.swift

Chapter1.playgroundchapter

Introduction.playgroundpage

HowDoesItWork.playgroundpage

Page 133: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

import PlaygroundSupport

let page = PlaygroundPage.current

page.liveView = FaceViewController()

Page 134: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

import PlaygroundSupport

let page = PlaygroundPage.current

page.liveView = FaceViewController()

Contents.swift

Page 135: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

In main process

import PlaygroundSupport

let page = PlaygroundPage.current

page.liveView = FaceViewController()

Contents.swift

Page 136: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

In main processOnly active while running

import PlaygroundSupport

let page = PlaygroundPage.current

page.liveView = FaceViewController()

Contents.swift

Page 137: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

In main processOnly active while running

import PlaygroundSupport

let page = PlaygroundPage.current

page.liveView = FaceViewController()

Contents.swift

Page 138: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

In main processOnly active while running

import PlaygroundSupport

let page = PlaygroundPage.current

page.liveView = FaceViewController()

Contents.swift LiveView.swift

import PlaygroundSupport

let page = PlaygroundPage.current

page.liveView = FaceViewController()

Page 139: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

In main processOnly active while running

import PlaygroundSupport

let page = PlaygroundPage.current

page.liveView = FaceViewController()

Contents.swift

Separate process

LiveView.swift

import PlaygroundSupport

let page = PlaygroundPage.current

page.liveView = FaceViewController()

Page 140: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

In main processOnly active while running

import PlaygroundSupport

let page = PlaygroundPage.current

page.liveView = FaceViewController()

Contents.swift

Separate processRunning all the time

LiveView.swift

import PlaygroundSupport

let page = PlaygroundPage.current

page.liveView = FaceViewController()

Page 141: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

import PlaygroundSupport

let page = PlaygroundPage.current

if let proxy = page.liveView as? PlaygroundRemoteLiveViewProxy {

let message: PlaygroundValue = .string("Knock, knock!")

proxy.send(message)

}

Main Process (Contents.swift)

Page 142: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

import PlaygroundSupport

let page = PlaygroundPage.current

if let proxy = page.liveView as? PlaygroundRemoteLiveViewProxy {

let message: PlaygroundValue = .string("Knock, knock!")

proxy.send(message)

}

Main Process (Contents.swift)

Page 143: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

import PlaygroundSupport

let page = PlaygroundPage.current

if let proxy = page.liveView as? PlaygroundRemoteLiveViewProxy {

let message: PlaygroundValue = .string("Knock, knock!")

proxy.send(message)

}

Main Process (Contents.swift)

Page 144: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

import PlaygroundSupport

let page = PlaygroundPage.current

if let proxy = page.liveView as? PlaygroundRemoteLiveViewProxy {

let message: PlaygroundValue = .string("Knock, knock!")

proxy.send(message)

}

Main Process (Contents.swift)

Page 145: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

import PlaygroundSupport

let page = PlaygroundPage.current

if let proxy = page.liveView as? PlaygroundRemoteLiveViewProxy {

let message: PlaygroundValue = .string("Knock, knock!")

proxy.send(message)

}

Main Process (Contents.swift)

Page 146: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

import PlaygroundSupport

let page = PlaygroundPage.current

if let proxy = page.liveView as? PlaygroundRemoteLiveViewProxy {

let message: PlaygroundValue = .string("Knock, knock!")

proxy.send(message)

}

Main Process (Contents.swift)

Page 147: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Sending to the Live View Process

Live View ProxyContents.swift FaceViewController

Page 148: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Sending to the Live View Process

Live View ProxyContents.swift FaceViewController

Page 149: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Sending to the Live View Process

Live View ProxyContents.swift FaceViewController

Page 150: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

extension FaceViewController: PlaygroundLiveViewMessageHandler {

public func receive(_ message: PlaygroundValue) {

if case let .string(text) = message {

processConversationLine(text)

}

}

}

Live View Process (LiveView.swift)

Page 151: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

extension FaceViewController: PlaygroundLiveViewMessageHandler {

public func receive(_ message: PlaygroundValue) {

if case let .string(text) = message {

processConversationLine(text)

}

}

}

Live View Process (LiveView.swift)

Page 152: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

extension FaceViewController: PlaygroundLiveViewMessageHandler {

public func receive(_ message: PlaygroundValue) {

if case let .string(text) = message {

processConversationLine(text)

}

}

}

Live View Process (LiveView.swift)

Page 153: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

extension FaceViewController: PlaygroundLiveViewMessageHandler {

public func receive(_ message: PlaygroundValue) {

if case let .string(text) = message {

processConversationLine(text)

}

}

}

Live View Process (LiveView.swift)

Page 154: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

extension FaceViewController: PlaygroundLiveViewMessageHandler {

public func receive(_ message: PlaygroundValue) {

if case let .string(text) = message {

processConversationLine(text)

}

}

}

Live View Process (LiveView.swift)

Page 155: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Sending from the Live View Process

Live View ProxyContents.swift FaceViewController

Page 156: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Sending from the Live View Process

Live View ProxyContents.swift FaceViewController?

Page 157: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

extension FaceViewController: PlaygroundLiveViewMessageHandler {

public func tapped() {

let message: PlaygroundValue = .string("Hello!")

send(message)

}

}

Live View Process (LiveView.swift)

Page 158: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

extension FaceViewController: PlaygroundLiveViewMessageHandler {

public func tapped() {

let message: PlaygroundValue = .string("Hello!")

send(message)

}

}

Live View Process (LiveView.swift)

Page 159: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

extension FaceViewController: PlaygroundLiveViewMessageHandler {

public func tapped() {

let message: PlaygroundValue = .string("Hello!")

send(message)

}

}

Live View Process (LiveView.swift)

Page 160: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

extension FaceViewController: PlaygroundLiveViewMessageHandler {

public func tapped() {

let message: PlaygroundValue = .string("Hello!")

send(message)

}

}

Live View Process (LiveView.swift)

Page 161: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

extension FaceViewController: PlaygroundLiveViewMessageHandler {

public func tapped() {

let message: PlaygroundValue = .string("Hello!")

send(message)

}

}

Live View Process (LiveView.swift)

Page 162: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Sending from the Live View Process

Contents.swift FaceViewControllerLive View Proxy

Page 163: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Sending from the Live View Process

Contents.swift FaceViewControllerLive View Proxy

Page 164: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Sending from the Live View Process

Contents.swift FaceViewController?

Live View Proxy

Page 165: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Main Process (Contents.swift)

let page = PlaygroundPage.current

page.needsIndefiniteExecution = true

let proxy = page.liveView as? PlaygroundRemoteLiveViewProxy

class MyClassThatListens: PlaygroundRemoteLiveViewProxyDelegate {

func remoteLiveViewProxy(_ remoteLiveViewProxy: PlaygroundRemoteLiveViewProxy,

received message: PlaygroundValue) {

if case let .string(text) = message {

doSomethingWithString(text)

}

}

}

let listener = MyClassThatListens()

proxy?.delegate = listener

Page 166: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Main Process (Contents.swift)

let page = PlaygroundPage.current

page.needsIndefiniteExecution = true

let proxy = page.liveView as? PlaygroundRemoteLiveViewProxy

class MyClassThatListens: PlaygroundRemoteLiveViewProxyDelegate {

func remoteLiveViewProxy(_ remoteLiveViewProxy: PlaygroundRemoteLiveViewProxy,

received message: PlaygroundValue) {

if case let .string(text) = message {

doSomethingWithString(text)

}

}

}

let listener = MyClassThatListens()

proxy?.delegate = listener

Page 167: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Main Process (Contents.swift)

let page = PlaygroundPage.current

page.needsIndefiniteExecution = true

let proxy = page.liveView as? PlaygroundRemoteLiveViewProxy

class MyClassThatListens: PlaygroundRemoteLiveViewProxyDelegate {

func remoteLiveViewProxy(_ remoteLiveViewProxy: PlaygroundRemoteLiveViewProxy,

received message: PlaygroundValue) {

if case let .string(text) = message {

doSomethingWithString(text)

}

}

}

let listener = MyClassThatListens()

proxy?.delegate = listener

Page 168: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Main Process (Contents.swift)

let page = PlaygroundPage.current

page.needsIndefiniteExecution = true

let proxy = page.liveView as? PlaygroundRemoteLiveViewProxy

class MyClassThatListens: PlaygroundRemoteLiveViewProxyDelegate {

func remoteLiveViewProxy(_ remoteLiveViewProxy: PlaygroundRemoteLiveViewProxy,

received message: PlaygroundValue) {

if case let .string(text) = message {

doSomethingWithString(text)

}

}

}

let listener = MyClassThatListens()

proxy?.delegate = listener

Page 169: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Main Process (Contents.swift)

let page = PlaygroundPage.current

page.needsIndefiniteExecution = true

let proxy = page.liveView as? PlaygroundRemoteLiveViewProxy

class MyClassThatListens: PlaygroundRemoteLiveViewProxyDelegate {

func remoteLiveViewProxy(_ remoteLiveViewProxy: PlaygroundRemoteLiveViewProxy,

received message: PlaygroundValue) {

if case let .string(text) = message {

doSomethingWithString(text)

}

}

}

let listener = MyClassThatListens()

proxy?.delegate = listener

Page 170: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Main Process (Contents.swift)

let page = PlaygroundPage.current

page.needsIndefiniteExecution = true

let proxy = page.liveView as? PlaygroundRemoteLiveViewProxy

class MyClassThatListens: PlaygroundRemoteLiveViewProxyDelegate {

func remoteLiveViewProxy(_ remoteLiveViewProxy: PlaygroundRemoteLiveViewProxy,

received message: PlaygroundValue) {

if case let .string(text) = message {

doSomethingWithString(text)

}

}

}

let listener = MyClassThatListens()

proxy?.delegate = listener

Page 171: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Main Process (Contents.swift)

let page = PlaygroundPage.current

page.needsIndefiniteExecution = true

let proxy = page.liveView as? PlaygroundRemoteLiveViewProxy

class MyClassThatListens: PlaygroundRemoteLiveViewProxyDelegate {

func remoteLiveViewProxy(_ remoteLiveViewProxy: PlaygroundRemoteLiveViewProxy,

received message: PlaygroundValue) {

if case let .string(text) = message {

doSomethingWithString(text)

}

}

}

let listener = MyClassThatListens()

proxy?.delegate = listener

Page 172: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Main Process (Contents.swift)

let page = PlaygroundPage.current

page.needsIndefiniteExecution = true

let proxy = page.liveView as? PlaygroundRemoteLiveViewProxy

class MyClassThatListens: PlaygroundRemoteLiveViewProxyDelegate {

func remoteLiveViewProxy(_ remoteLiveViewProxy: PlaygroundRemoteLiveViewProxy,

received message: PlaygroundValue) {

if case let .string(text) = message {

doSomethingWithString(text)

}

}

}

let listener = MyClassThatListens()

proxy?.delegate = listener

Page 173: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Main Process (Contents.swift)

let page = PlaygroundPage.current

page.needsIndefiniteExecution = true

let proxy = page.liveView as? PlaygroundRemoteLiveViewProxy

class MyClassThatListens: PlaygroundRemoteLiveViewProxyDelegate {

func remoteLiveViewProxy(_ remoteLiveViewProxy: PlaygroundRemoteLiveViewProxy,

received message: PlaygroundValue) {

if case let .string(text) = message {

doSomethingWithString(text)

}

}

}

let listener = MyClassThatListens()

proxy?.delegate = listener

Page 174: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Sending from the Live View Process

Contents.swift FaceViewControllerLive View Proxy

Page 175: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Sending from the Live View Process

Contents.swift FaceViewControllerLive View Proxy

Page 176: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Sending from the Live View Process

Contents.swift FaceViewControllerLive View Proxy

Page 177: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

// Playground Values

public enum PlaygroundValue {

case array([PlaygroundValue])

case dictionary([String: PlaygroundValue])

case string(String)

case data(Data)

case date(Date)

case integer(Int)

case floatingPoint(Double)

case boolean(Bool)

}

Page 178: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

// Key/Value Store

import PlaygroundSupport

let store = PlaygroundPage.current.keyValueStore

store["Greeting"] = .string("Hello, WWDC!")

if case let .string(greeting)? = store["Greeting"] {

print(greeting) // "Hello, WWDC!"

}

Page 179: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

1024 x 768Contents.swift

Page 180: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

1024 x 768Contents.swift LiveView.swift

Page 181: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Contents

ResourcesSources

Chapter1Pages

Chapters

Introduction

HowDoesItWork

Manifest.plistContents.swiftLiveView.swift

Chapter1.playgroundchapter

Introduction.playgroundpage

HowDoesItWork.playgroundpage

Page 182: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Contents

ResourcesSources

Chapter1Pages

Chapters

Introduction

HowDoesItWork

Manifest.plistContents.swiftLiveView.swift

Chapter1.playgroundchapter

Introduction.playgroundpage

HowDoesItWork.playgroundpage

Page 183: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

EditsContents

ResourcesSources

Chapter1Pages

Chapters

Introduction

HowDoesItWork

Manifest.plistContents.swiftLiveView.swift

Chapter1.playgroundchapter

Introduction.playgroundpage

HowDoesItWork.playgroundpage

Page 184: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer
Page 185: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

developer.apple.com

Page 186: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

1024 x 768

Page 187: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

DemoGrowing and Exploring

Izzy FraimowPlaygrounds Engineer

Page 188: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

SummarySwift Playgrounds

Page 189: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

SummarySwift Playgrounds

Touch-focused experience for experimenting with Swift

Page 190: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

SummarySwift Playgrounds

Touch-focused experience for experimenting with SwiftRich new document format for creating engaging content

Page 191: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

SummarySwift Playgrounds

Touch-focused experience for experimenting with SwiftRich new document format for creating engaging contentPowerful access to iOS SDK

Page 192: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Playgrounds

Page 193: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

More Information

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

Page 194: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Related Sessions

Keynote Bill Graham Monday 10:00AM

Platforms State of the Union Bill Graham Monday 2:30PM

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

Page 195: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer

Labs

Swift Open Hours Developer Tools Lab A Tuesday 12:00PM

Swift Open Hours Developer Tools Lab A

Wednesday–Friday 9:00AM

Creating Content for Swift Playgrounds Dev Tools Lab C Wednesday 12:00PM

Xcode Open Hours Developer Tools Labs B Wednesday 3:00PM

Xcode Open Hours Developer Tools Labs C Thursday 9:00AM

Creating Content for Swift Playgrounds Dev Tools Lab C Friday 12:00PM

Page 196: Introducing Swift Playgrounds - Apple Developer · Exploring with Swift on iPad Developer Tools #WWDC16 Session 408 Introducing Swift Playgrounds Matt Patenaude Playgrounds Engineer