Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up
for free
How to make and publish a Swift playground book for iPad
sonson
September 01, 2018
Programming
5
15k
How to make and publish a Swift playground book for iPad
sonson
September 01, 2018
Tweet
Share
More Decks by sonson
See All by sonson
sonsongithub
2
230
sonsongithub
0
530
sonsongithub
1
240
sonsongithub
0
150
sonsongithub
3
5.1k
sonsongithub
0
200
sonsongithub
0
310
sonsongithub
3
460
Other Decks in Programming
See All in Programming
n1215
1
490
dqneo
0
150
timeseriesfr
0
150
kilometer
2
300
deepu105
1
200
kentatada
0
120
yattom
32
11k
yasuakiomokawa
0
660
ajstarks
2
760
rgoswami
1
110
bosshawk
1
280
imk2o
0
210
Featured
See All Featured
robhawkes
53
2.9k
davidbonilla
71
3.6k
rasmusluckow
318
19k
paulrobertlloyd
71
3.7k
eileencodes
114
25k
phodgson
88
4k
bkeepers
PRO
409
58k
afnizarnur
178
14k
philnash
10
680
hursman
108
9.3k
geoffreycrofte
27
1k
jonyablonski
22
1.3k
Transcript
Χϝϥ͔Βͷը૾ΛϦΞϧλΠϜʹ͍͡ΔPlayPixels Tech. Yuichi Yoshida Senior researcher, DENSO IT Laboratory, Inc.
#iOSDC2018 @sonson_twit © 2014 DENSO IT Laboratory, Inc., All rights reserved. Redistribution or public display not permitted without written permission from DENSO IT Laboratory, Inc. Swift Playgrounds Bookͷ࡞ΓํͱΓํ
ࣗݾհ • sonson • twitter: sonson_twit • github: sonsongithub •
portfolio • 2tchɾɾɾଟɼࣙΊΔ • numsw • iOS11 Programming Book(ൃചத) • ࣄ(computer vision, machine learning) • ը૾ೝࣝɾݕࡧٕज़ • ࠷ۙσʔλαΠΤϯεతͳ͜ͱ
$PSF.-ͱ$SFBUF.-ʹ ͍ͭͯॻ͘Α
ࠓͷత
Swift Playgrounds
None
σϞ • AppleͷσϞ
ࠓͷ͓ • త • iPadʹࣗΈͷSwift codingڥΛ࡞Δ • ͦ͏͍͏ڥΛΈΜͳͰެ։͋ͬͯ͠ɼָ͠Ή • ࡞Γํͱެ։ํ๏
• AppleۘͷςϯϓϨʔτʹΑΔ࡞ΓํΛհ • ެ։Ͱ͖ΔΜͰ͢Αɼ͜Ε͕ɽ • Χϝϥͷը૾ॲཧΛ͢Δαϯϓϧ • ը૾ॲཧͷࠜװΛͬͯΒ͏
͜͏͍͏ͷΛΈΜͳͰ • ରʢ͓͢͢Ίʣ • Binary searchͷσϞ • ֆจࣈॲཧͷσϞ • numsw
- ઢܗ • PlayPixelsʢࠓͷϝΠϯσΟογϡʣ
͍͍ͱ͜Ζ • ϝΠϯͷతڭҭΒ͍͠ • ͰͶ͐ɾɾίϯςϯπ࡞Δͷେม • iPadͰಈ͘ʂʂʂ • Ͳ͜Ͱίʔυ͕ॻ͚Δ •
͓खܰɼ͔ͬ͜Α͘σϞͰ͖Δ • ͲΜͲΜਐԽ͍ͯ͠Δ • Χϝϥ͕͑ΔΑ͏ʹͳͬͨʂ • Bluetooth͕͑ΔΑ͏ʹͳͬͨʂ
ͭΒ͍ͱ͜Ζ • ϑϨʔϜϫʔΫϥΠϒϥϦ͕͑ͳ͍ • ͯ͢ιʔείʔυΦʔϓϯʹͳͬͯ͠·͏ • σόοά͕େม • Ϛγʹͳ͖ͬͯͨ •
AppleLEGOͷίϯςϯπ͕͗͢͢͝Δ • ૉਓ͕࡞Δͱɼ൵͍͠ɾɾɾɾ
PlaygroundBookͷ࡞Γํ
PlaygroundBook
Playgroundbookͷߏ ├── Chapters │ └── Chapter1.playgroundchapter │ ├── Manifest.plist │
└── Pages │ ├── Basic.playgroundpage │ │ ├── Contents.swift │ │ ├── LiveView.swift │ │ └── Manifest.plist │ ├── Binarize.playgroundpage │ │ ├── Contents.swift │ │ ├── LiveView.swift │ │ └── Manifest.plist │ └── Filter.playgroundpage │ ├── Contents.swift │ ├── LiveView.swift │ └── Manifest.plist ├── Manifest.plist ├── PrivateResources │ ├── Base.lproj │ │ └── LiveView.storyboard │ ├── en.lproj │ │ └── ManifestPlist.strings │ └── icon.png └── Sources ├── LiveViewController.swift └── LiveViewSupport.swift
֓ཁ -JWF7JFXTXJGU $POUFOUTTXJGU
࡞Γํ • AppleͷςϯϓϨʔτΛ͏ʢమଇʣ • Swift Playgrounds Author Template for Xcode
9.3Λσ ϕϩούʔαΠτ͔Βμϯϩʔυ
·ͣઃఆ • README.mdͷ”First Step”ʹै͍ɼϓϩδΣΫτͷ໊લ ͱ͔Λมߋ͢Δ • దʹΔͱ໘ष͍͜ͱʹͳΔͷͰҙ • AppleͷςϯϓϨ͔ͳΓνϡʔϯ͞ΕͯΔɾɾɾʁ
ϓϩδΣΫτͷ ໊લͳͲͷม ·ͣಡΉ Ͱͳ͍ͱϋϚΔ γϛϡϨʔλ্Ͱ#MVFUPPUI ͳͲΛ࠶ݱ͢ΔͨΊͷπʔϧ-JC γϛϡϨʔλΞϓϦຊମ 1MBZHSPVOE#PPL ຊମ
Swift Playgrounds Author Template • ΞϓϦͱͯ͠BookΛಈ͔͠ɼσόοά͘͢͠ • BluetoothͷUIΛΤϛϡϨʔτ • ϏϧυεΫϦϓτࠐΈ
• σόοά • iOS12ͰSwift PlaygroundsͰNSLogΛ࣮ߦͯ͠Կ දࣔ͞Εͳ͍ɾɾɾɾ • ͜ͷςϯϓϨʔτ͕།Ұͷ։ൃڥɾɾɾɾ
λʔήοτ 4XJGU1MBZHSPVOE#PPL
λʔήοτ #PPLͷγϛϡϨʔλͱͯ͠ͷΞϓϦ
λʔήοτ ΞϓϦͷͨΊʹίʔυΛ-JCʹ
-JWF7JFX5FTUBQQͷͨΊͷ ϑϨʔϜϫʔΫ
ͷத
Playgroundbookͷߏ ├── Chapters │ └── Chapter1.playgroundchapter │ ├── Manifest.plist │
└── Pages │ ├── Basic.playgroundpage │ │ ├── Contents.swift │ │ ├── LiveView.swift │ │ └── Manifest.plist │ ├── Binarize.playgroundpage │ │ ├── Contents.swift │ │ ├── LiveView.swift │ │ └── Manifest.plist │ └── Filter.playgroundpage │ ├── Contents.swift │ ├── LiveView.swift │ └── Manifest.plist ├── Manifest.plist ├── PrivateResources │ ├── Base.lproj │ │ └── LiveView.storyboard │ ├── en.lproj │ │ └── ManifestPlist.strings │ └── icon.png └── Sources ├── LiveViewController.swift └── LiveViewSupport.swift
Playgroundbookͷߏ ├── Chapters │ └── Chapter1.playgroundchapter │ ├── Manifest.plist │
└── Pages │ ├── Basic.playgroundpage │ │ ├── Contents.swift │ │ ├── LiveView.swift │ │ └── Manifest.plist │ ├── Binarize.playgroundpage │ │ ├── Contents.swift │ │ ├── LiveView.swift │ │ └── Manifest.plist │ └── Filter.playgroundpage │ ├── Contents.swift │ ├── LiveView.swift │ └── Manifest.plist ├── Manifest.plist ├── PrivateResources │ ├── Base.lproj │ │ └── LiveView.storyboard │ ├── en.lproj │ │ └── ManifestPlist.strings │ └── icon.png └── Sources ├── LiveViewController.swift └── LiveViewSupport.swift ຊମ
Playgroundbookͷߏ ├── Chapters │ └── Chapter1.playgroundchapter │ ├── Manifest.plist │
└── Pages │ ├── Basic.playgroundpage │ │ ├── Contents.swift │ │ ├── LiveView.swift │ │ └── Manifest.plist │ ├── Binarize.playgroundpage │ │ ├── Contents.swift │ │ ├── LiveView.swift │ │ └── Manifest.plist │ └── Filter.playgroundpage │ ├── Contents.swift │ ├── LiveView.swift │ └── Manifest.plist ├── Manifest.plist ├── PrivateResources │ ├── Base.lproj │ │ └── LiveView.storyboard │ ├── en.lproj │ │ └── ManifestPlist.strings │ └── icon.png └── Sources ├── LiveViewController.swift └── LiveViewSupport.swift ϖʔδ ࠷খ୯Ґ
Playgroundbookͷߏ ├── Chapters │ └── Chapter1.playgroundchapter │ ├── Manifest.plist │
└── Pages │ ├── Basic.playgroundpage │ │ ├── Contents.swift │ │ ├── LiveView.swift │ │ └── Manifest.plist │ ├── Binarize.playgroundpage │ │ ├── Contents.swift │ │ ├── LiveView.swift │ │ └── Manifest.plist │ └── Filter.playgroundpage │ ├── Contents.swift │ ├── LiveView.swift │ └── Manifest.plist ├── Manifest.plist ├── PrivateResources │ ├── Base.lproj │ │ └── LiveView.storyboard │ ├── en.lproj │ │ └── ManifestPlist.strings │ └── icon.png └── Sources ├── LiveViewController.swift └── LiveViewSupport.swift ֤ϖʔδͷઃఆ
Playgroundbookͷߏ ├── Chapters │ └── Chapter1.playgroundchapter │ ├── Manifest.plist │
└── Pages │ ├── Basic.playgroundpage │ │ ├── Contents.swift │ │ ├── LiveView.swift │ │ └── Manifest.plist │ ├── Binarize.playgroundpage │ │ ├── Contents.swift │ │ ├── LiveView.swift │ │ └── Manifest.plist │ └── Filter.playgroundpage │ ├── Contents.swift │ ├── LiveView.swift │ └── Manifest.plist ├── Manifest.plist ├── PrivateResources │ ├── Base.lproj │ │ └── LiveView.storyboard │ ├── en.lproj │ │ └── ManifestPlist.strings │ └── icon.png └── Sources ├── LiveViewController.swift └── LiveViewSupport.swift ຊͷߏ
Playgroundbookͷߏ ├── Chapters │ └── Chapter1.playgroundchapter │ ├── Manifest.plist │
└── Pages │ ├── Basic.playgroundpage │ │ ├── Contents.swift │ │ ├── LiveView.swift │ │ └── Manifest.plist │ ├── Binarize.playgroundpage │ │ ├── Contents.swift │ │ ├── LiveView.swift │ │ └── Manifest.plist │ └── Filter.playgroundpage │ ├── Contents.swift │ ├── LiveView.swift │ └── Manifest.plist ├── Manifest.plist ├── PrivateResources │ ├── Base.lproj │ │ └── LiveView.storyboard │ ├── en.lproj │ │ └── ManifestPlist.strings │ └── icon.png └── Sources ├── LiveViewController.swift └── LiveViewSupport.swift Ϧιʔε
Playgroundbookͷߏ ├── Chapters │ └── Chapter1.playgroundchapter │ ├── Manifest.plist │
└── Pages │ ├── Basic.playgroundpage │ │ ├── Contents.swift │ │ ├── LiveView.swift │ │ └── Manifest.plist │ ├── Binarize.playgroundpage │ │ ├── Contents.swift │ │ ├── LiveView.swift │ │ └── Manifest.plist │ └── Filter.playgroundpage │ ├── Contents.swift │ ├── LiveView.swift │ └── Manifest.plist ├── Manifest.plist ├── PrivateResources │ ├── Base.lproj │ │ └── LiveView.storyboard │ ├── en.lproj │ │ └── ManifestPlist.strings │ └── icon.png └── Sources ├── LiveViewController.swift └── LiveViewSupport.swift Ұ൪େ ڞ௨ͷΫϥεͱ͔
playgroundpageͷߏཁૉ • LiveView.swift • Contents.swift • Manifest.plist
LiveView.swift • LiveView.swiftʹॻ͘͜ͱ͋Μ·Γͳ͍ • LiveViewControllerΛ͜͜Ͱੜ • receiveͰίϯτϩʔϥ͔ΒσʔλΛ͏͚ͱΓඳը • ॏཁͳͷɼLiveViewControllerͷ࣮ import
UIKit import PlaygroundSupport PlaygroundPage.current.liveView = sharedLiveViewController
Contents.swift • ίʔσΟϯάʹؔ͢Δίϝϯτώϯτɼεέϧτϯίʔυ • ษڧͱͯ͠ͷίϯςϯπͪ͜Β͕ओ //#-hidden-code import UIKit import PlaygroundSupport
//#-end-hidden-code func process(input: UnsafePointer<CUnsignedChar>, output: inout [CUnsignedChar], width: Int, height: Int, bytesPerPixel: Int) { //#-editable-code // write your own code //#-end-editable-code } //#-hidden-code class Listener: PlaygroundRemoteLiveViewProxyDelegate { func remoteLiveViewProxy(_ remoteLiveViewProxy: PlaygroundRemoteLiveViewProxy, received message: PlaygroundValue) { // handle message from LiveViewController } } let listener = Listener() if let proxy = page.liveView as? PlaygroundRemoteLiveViewProxy { proxy.delegate = listener } //#-end-hidden-code
Manifest.plist - Page 1MBZHSPVOE-PHHJOH.PEF0⒎ -JWF7JFX&EHF5P&EHF:&4
Manifest.plist - Page 1MBZHSPVOE-PHHJOH.PEF/PSNBM -JWF7JFX&EHF5P&EHF:&4
Manifest.plist - Page 1MBZHSPVOE-PHHJOH.PEF0⒎ -JWF7JFX&EHF5P&EHF:&4
cutscenepageͷߏཁૉ • playgroundpageͱҟͳΓHTMLදࣔՄೳ • ϑΥϧμ໊ɹ00.cutscenepage • Manifest.plistʹHTMLΛࢦఆ • PrivateResourcesʹݴޠ͝ͱʹHTMLΛ༻ҙ͢Δ •
ίʔυෆཁͷϜʔϏʔͬΆ͍ͷʹ͏Α͏ͩ
جຊίϯηϓτ -JWF7JFXͷϓϩηε $POUFOUͷϓϩηε
جຊίϯηϓτ -JWF7JFXͷϓϩηε $POUFOUͷϓϩηε
جຊίϯηϓτ -JWF7JFXͷϓϩηε $POUFOUͷϓϩηε 1SPYZ
ૹΔͱ͖྆ํͱಉ͡ -JWF7JFXͷϓϩηε $POUFOUͷϓϩηε 1SPYZ TFOE @NFTTBHF1MBZHSPVOE7BMVF
ૹड৴Ͱ͖Δܕ public enum PlaygroundValue { case array([PlaygroundSupport.PlaygroundValue]) case dictionary([String :
PlaygroundSupport.PlaygroundValue]) case string(String) case data(Data) case date(Date) case integer(Int) case floatingPoint(Double) case boolean(Bool) }
ૹΔͱ͖྆ํͱಉ͡ -JWF7JFXͷϓϩηε $POUFOUͷϓϩηε 1SPYZ TFOE @NFTTBHF1MBZHSPVOE7BMVF
ड৴͚͕ͩҟͳΔ $POUFOUͷϓϩηε class Listener: PlaygroundRemoteLiveViewProxyDelegate { var pixelBuffer24bit: [CUnsignedChar]? func
remoteLiveViewProxy(_ remoteLiveViewProxy: PlaygroundRemoteLiveViewProxy, received message: PlaygroundValue) { // handle a message } func remoteLiveViewProxyConnectionClosed(_ remoteLiveViewProxy: PlaygroundRemoteLiveViewProxy) { } } let listener = Listener() if let proxy = page.liveView as? PlaygroundRemoteLiveViewProxy { proxy.delegate = listener }
ૹΔͱ͖྆ํͱಉ͡ -JWF7JFXͷϓϩηε $POUFOUͷϓϩηε 1SPYZ TFOE @NFTTBHF1MBZHSPVOE7BMVF
ड৴͚͕ͩҟͳΔ -JWF7JFXͷϓϩηε @objc(Book_Sources_LiveViewController) public class LiveViewController: UIViewController, PlaygroundLiveViewMessageHandler, PlaygroundLiveViewSafeAreaContainer {
public func receive(_ message: PlaygroundValue) { update(message) } }
جຊίϯηϓτ -JWF7JFXͷϓϩηε $POUFOUͷϓϩηε 1SPYZ
PlayPixelsͷ߹ -JWF7JFXͷϓϩηε $POUFOUͷϓϩηε 1SPYZ ը૾ॲཧ $BNFSB ͜ͷॲཧͷίʔυ $POUFOUTTXJGU Ωϟϓνϟͨ͠ ը૾Λ%BUBʹ
PlayPixelsͷ߹ -JWF7JFXͷϓϩηε $POUFOUͷϓϩηε 1SPYZ %BUBʹ ύοΩϯά 6**NBHFʹ 6**NBHF7JFXʹηοτ
LiveViewTest.app • UIApplicationΛվʁ • LiveViewControllerͷಈ࡞֬ೝ༻ͷΞϓϦ • Swift Playgroundsઐ༻ͷUIͷςετ • ͦͷͨΊͷBluetoothͳͲͷϑϨʔϜϫʔΫ
• Contents.swiftͷཧίʔυͷ࣮͕ඞཁ ͏͖ɽσόοάͰࢮͶΔ #if LiveViewTestApp // γϛϡϨʔλͰಈ͔͢ͱ͖ɼϝιουΛͰୟ͖ɼContents.swiftͷΘΓΛ࣮ߦ self.update(value) #else // PlaygroundͰಈ͔͢ͱ͖ɼproxyܦ༝ͰContents.swiftʹσʔλΛૹΔ self.send(value) #endif
Playground Book • PlaygroundSupportͱݺΕΔϞδϡʔϧ͕৭ʑػೳΛఏڙ • ςϯϓϨʔτͰγϛϡϨʔγϣϯՄೳ • PlaygroundValueܕͰͤΔσʔλͷܕͷόϦΤʔγϣϯ͕গͳ͍ • ؔͱ͔ͤͳ͍
• LiveViewTest.appɼContents.swiftͱແؔ • ίϯςϯπΛ͏·͘දࣔͤ͞ΔͨΊͷςετίʔυ͕ඞཁ
։ൃͷྲྀΕʁ • TemplateΛฤू • LiveViewControllerΛ࣮ • AppDelegate.swiftͰίϯςϯπΛදࣔ͢ΔίʔυΛ ॻ͘(Contents.swift) • iPad࣮ػͰɼLiveViewTest.appΛςετ
• PlaygroundBookΛϏϧυ • AirDropͰiPad࣮ػʹPlaygroundBookΛૹΔ • Swift PlaygroundsͰ࣮ߦ͢Δ
υΩϡϝϯτ • Playground Book Format Reference • Swift PlaygroundsͷϓϩδΣΫτࣗମ͕ιʔεͷๅݿ
Furthermore, • Contents.swiftͷৄ͍͠ઃఆ • ίϯςϯπ࡞ΓͶ • ଟݴޠԽʢَʣ • Key-value store͋Δ
• AssesmentStatus • ϢʔβͷਐḿධՁ༻ͷΈʁ
PlaygroundBookΛެ։͢Δ
ެ։ํ๏ • ࠷ۙͬͱެ։Ͱ͖ΔΑ͏ʹͳͬͨ • Ϣʔβ͕Swift Playgrounds͔ΒfeedΛొՄೳ • ϒϥβ͔Βొ͢Δ͜ͱͰ͖Δ
खॱ • ެ։ͷͨΊͷjsonϑΝΠϧ(feed)Λ࡞Δ • BookΛෳݸऩΊΒΕΔ • ϋϚΔϙΠϯτ • λΠτϧͱ໊લ͕Ұக •
λΠτϧͱղౚޙͷ໊લ͕Ұக • identifier͕Ұக
feed { "title": "sonson", "publisherName": "Yuichi Yoshida", "feedIdentifier": "com.sonson.playground", "contactURL":
"mailto:hoge@hoge.com", "formatVersion": "1.0", "documents": [ { "title": "PlayPixels", "overviewSubtitle": "To be written.", "detailSubtitle": "αϒλΠτϧৄࡉ", "description": "ৄ͍͠આ໌", "contentIdentifier": "com.sonson.playground.PlayPixels", "contentVersion": "1.0", "url": "https://sonson.jp/playgrounds/playpixels/PlayPixels.playgroundbook.zip", "publishedDate": "2018-05-18T12:00:00+00:00", "lastUpdatedDate": "2018-05-18T12:00:00+00:00", "thumbnailURL": "playpixels/thumbnail.png", "bannerImageURL": "playpixels/thumbnail.png", "additionalInformation": [ { "name": "Languages", "value": "English" } ], "previewImageURLs": [] } ] }
खॱ • ެ։ͷͨΊͷjsonϑΝΠϧ(feed)Λ࡞Δ • BookΛෳݸऩΊΒΕΔ • ϋϚΔϙΠϯτ • λΠτϧͱ໊લ͕Ұக •
λΠτϧͱղౚޙͷ໊લ͕Ұக • identifier͕Ұக • feedʹࢦఆͨ͠ύεʹzipͰݻΊͨbookϑΝΠϧΛஔ͘ ├── feed.json ├── index.html └── playpixels ├── PlayPixels.playgroundbook.zip └── thumbnail.png
ϒϥβ͔ΒμΠϨΫτʹొ "https://developer.apple.com/ul/sp0?url=https://sonson.jp/playgrounds/feed.json"
https://sonson.jp/playgrounds/
Swift Playgrounds͕ىಈ
ొɾɾɾɾײಈ
PlayPixelsͰֶͿը૾ॲཧͷجຊ
https://github.com/sonsongithub/PlayPixels
ը૾ॲཧͷجຊ
ը૾ॲཧͷجຊ
ը૾ॲཧͷجຊ
ը૾ॲཧͷجຊ
ΈࠐΈԋࢉʔϑΟϧλ ೖྗը૾ ग़ྗը૾
ϑΟϧλ
ΈࠐΈԋࢉʔϑΟϧλ ೖྗը૾ ग़ྗը૾
ΈࠐΈԋࢉʔϑΟϧλ ೖྗը૾ ग़ྗը૾
º
ΈࠐΈԋࢉʔϑΟϧλ ೖྗը૾ ग़ྗը૾
ΈࠐΈԋࢉʔϑΟϧλ ೖྗը૾ ग़ྗը૾
ΈࠐΈԋࢉʔϑΟϧλ ೖྗը૾ ग़ྗը૾
ΈࠐΈԋࢉʔϑΟϧλ ೖྗը૾ ग़ྗը૾
ϑΟϧλͷαΠζͰ ͪΐͬͱখ͘͞ͳΔ
͜ΕɾɾɾͲΜͳϑΟϧλʁ
࣮ ܀ాଟتɺึতଠ, ύλʔϯೝࣝ ૣҴాେֶߨٛ – ฏ18
ྲྀߦΓͷCNN Y. Lecun, L. Bottou, Y. Bengio and P. Haffner,
"Gradient-based learning applied to document recognition," in Proceedings of the IEEE, vol. 86, no. 11, pp. 2278-2324, Nov. 1998. ͜ͷॏΈΛػցֶशͰಘΔ
·ͱΊ • Swift playgroundsͷָ͠͞ • Swift Playgrounds Author TemplateΛ͓͏ •
Bookͷجຊ • Proxyϕʔεͷϓϩάϥϛϯά • Feedͷઃఆ • ެ։ɼPlayground.appͰͰ͖Δʂ • PlayPixelsͰֶͿɼը૾ॲཧͷجຊ