Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
進化を続けるSwift-iOSに追随し続けるために
Search
Kohei Tabata
August 29, 2016
Programming
1
2.4k
進化を続けるSwift-iOSに追随し続けるために
Kohei Tabata
August 29, 2016
Tweet
Share
More Decks by Kohei Tabata
See All by Kohei Tabata
営業活動なしで継続的に案件を受注する方法 / how to get a contract without sales as a freelance
nerd0geek1
2
880
生体データを取り扱うアプリ開発の勘所
nerd0geek1
1
85
動線改善とステータス可視化で家庭内のストレスを軽減した話
nerd0geek1
3
4.1k
家庭をプロジェクトとして運営した話
nerd0geek1
2
4.1k
fastlaneの勉強会を主催して学んだこと、得たこと、悩んだこと
nerd0geek1
1
990
みんなで育てるprecheck
nerd0geek1
1
680
matchとは?match導入のメリット
nerd0geek1
4
540
Improve your workflow with Sketch plugin
nerd0geek1
3
1.3k
Looking back try! Swift 2017
nerd0geek1
0
570
Other Decks in Programming
See All in Programming
Quine, Polyglot, 良いコード
qnighy
4
640
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
180
みんなでプロポーザルを書いてみた
yuriko1211
0
260
ヤプリ新卒SREの オンボーディング
masaki12
0
130
Click-free releases & the making of a CLI app
oheyadam
2
120
Better Code Design in PHP
afilina
PRO
0
130
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
イベント駆動で成長して委員会
happymana
1
320
Macとオーディオ再生 2024/11/02
yusukeito
0
370
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
Featured
See All Featured
Site-Speed That Sticks
csswizardry
0
24
Building an army of robots
kneath
302
43k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Building Adaptive Systems
keathley
38
2.3k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
89
Why Our Code Smells
bkeepers
PRO
334
57k
How to Ace a Technical Interview
jacobian
276
23k
Six Lessons from altMBA
skipperchong
27
3.5k
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
Transcript
ਐԽΛଓ͚ΔSwift/iOSʹ ਵ͠ଓ͚ΔͨΊʹ 2016/08/29 AKIBA.swift×SwiftѪձ @ώΧϦΤ
ࣗݾհ ɾKohei Tabata(@nerd0geek1) ɾSaib Studio LLC ɾiOS/MacOS/tvOS Developer ɾFastlaneେ͖ ɾ࠷ۙɺϥΠϒϥϦ࡞ΓʹϋϚ͍ͬͯ·͢ɻ
Said Studio LLC Kohei Tabata Next! Remote quick-zip plus Sleeple
http://next.saib-stud.io
ͦΖͦΖळͰ͢Ͷɻ
ळͱ͍͑
ಡॻͷळ
৯ཉͷळ
ӡಈͷळ
৽OSͷळ
͔͠ࠓ
OS/Swift͕ ಉ࣌Ξοϓσʔτʂ
Կ४උΛ ͍ͯ͠ͳ͍ͱ
None
ͲͷΑ͏ʹiOS/Swiftͷ ਐԽʹै͢Δ͔
ࣗͷऔΓΈ ɾίΞػೳҎ֎ͷίʔυͷϞδϡʔϧԽ ɾςετʹΑΔૉૣ͍มߋݕ ɾprotocolΛར༻࣮ͨ͠ͷநԽ ɾΦϒδΣΫτίϯϙδγϣϯ ɹprotocol extensionΛར༻ͨ͠ෳࡶ͞ͷݮ
ίʔυͷϞδϡʔϧԽ ɾ΄ͱΜͲͷϓϩδΣΫτͰɺ࣮͢Δ͜ͱ͍͍ͩͨҰॹɻ ɾ൚༻తͳ෦ʹ͍ͭͯɺϥΠϒϥϦԽ͠ɺϞδϡʔϧͱͯ͠ ɹ͓͘͜ͱͰɺશϓϩδΣΫτʹ͓͍ͯDRYʹॻ͚Δɻ ɹʹOSɺSwiftͷมߋʹରͯ͠࠷খͷमਖ਼ͰରԠͰ͖Δɻ ɾIFఆٛˠ࣮ɾςετͷՃͷॱͰ࣮͢ΔͷͰɺૄ݁߹Ͱ ɹςελϒϧͳίʔυΛॻ͖͍͢ɻ
͜Μͳײ͡ Next! Remote quick-zip plus Next! for Mac TableView Manager
PlayList Player Swift Extensions Logger Pausable Timer
ςετʹΑΔૉૣ͍มߋݕ ɾApple༷ɺ͠ΕͬͱഁյతมߋΛೖΕΔ͜ͱ͕͋Δɻ ɹSwift1.2→Swift2.0ͷStringͷpathૢ࡞ܥϝιουͷഇࢭ ɹSwift2.0→Swift3.0ͷFoundationͷΫϥεˠߏମͷมߋͳͲɻ ɾςετΛՃ͢Δ͜ͱͰɺͦ͏͍ͬͨมߋʹΑΔڍಈͷมԽΛ ɹૉૣ͘ݕͰ͖ΔΑ͏ʹͳΔɻ ɹ
protocolΛར༻࣮ͨ͠ͷநԽ ྫɿ͋ΔViewɺ͋ΔViewModel͕NSUserDefaults ɹɹαʔυύʔςΟͷϥΠϒϥϦͷࢀরΛอ͍࣋ͯ͠Δ߹ ɹˠϞδϡʔϧ͕֎෦ʹґଘ͢ΔͨΊɺςετͰ͖ͳ͍ɻ ɹɹςετͰ͖ͨͱ͔ͯͬͨ͠Γɺޙ͕࢝େมɻɻɻ ViewModel A NSUserDefaults ViewModel B
Dropbox SDK
protocolΛར༻࣮ͨ͠ͷநԽ ྫɿ͋ΔViewɺ͋ΔViewModel͕NSUserDefaults ɹɹαʔυύʔςΟͷϥΠϒϥϦͷࢀরΛอ͍࣋ͯ͠Δ߹ ɹˠϞδϡʔϧ͕֎෦ʹґଘ͢ΔͨΊɺςετͰ͖ͳ͍ɻ ɹɹςετͰ͖ͨͱ͔ͯͬͨ͠Γɺޙ͕࢝େมɻɻɻ
protocolΛར༻࣮ͨ͠ͷநԽ ɾඞཁͳػೳΛ࣋ͭprotocolΛఆٛ(͜͜ͰLocalConfigType)ɻ ɾViewModel͔ΒprotocolΛࢀরɻ ɾ࣮ͰɺNSUserDefaultsΛ෦Ͱࢀর͢ΔLocalConfigΛ͢ ɾςετͰɺLocalConfigMockͰϞοΩϯά͢Δɻ ViewModel A var config: LocalConfigType
protocol LocalConfigType NSUserDefaults LocalConfig: LocalConfigType LocalConfigMock: LocalConfigType var dictionary: [String: AnyObject] ϓϩμΫγϣϯίʔυ ςετ
protocolΛར༻࣮ͨ͠ͷநԽ ɾprotocolΛར༻࣮ͨ͠ͷநԽɺґଘੑͷೖʹ͍ͭͯ ɹલهͷΑ͏ʹ࣮Ͱ͖Δ͕ɺSwiftͷframeworkଘࡏ͍ͯ͠Δɻ
protocolΛར༻࣮ͨ͠ͷநԽ ɾprotocolΛར༻࣮ͨ͠ͷநԽɺґଘੑͷೖʹ͍ͭͯ ɹલهͷΑ͏ʹ࣮Ͱ͖Δ͕ɺSwiftͷframeworkଘࡏ͍ͯ͠Δɻ ɾSwinjectɿେنϓϩδΣΫτͰͷཧʹ͍͍ͯΔͱͷ͜ͱɻ
ΦϒδΣΫτίϯϙδγϣϯͱ protocol extensionͰෳࡶ͞Λݮ
࣮ࡍͷϓϩμΫτΛྫʹ ϑΝΠϧҰཡը໘ Ϋϥυ্ͷ ϑΝΠϧҰཡը໘ ΫϥυΞοϓϩʔυ͢Δ ϑΝΠϧͷબը໘ ϑΝΠϧҠಈը໘
நԽ͢Δͱ A D C B
ѱ͍ઃܭ جఈΫϥε(ViewController) - ڞ௨ίϯϙʔωϯτͷ࡞ - ڞ௨ॲཧͷ࣮ߦ αϒΫϥε - ಠࣗίϯϙʔωϯτͷ࡞ -
ίϯϙʔωϯτͷϨΠΞτ - ಠࣗॲཧͷ࣮ߦ
ѱ͍ઃܭ͕ͳͥѱ͔͔ͬͨ ɾαϒΫϥεΛฤू͢ΔࡍʹɺجఈΫϥεͷ࣮Λؾʹ͢Δඞཁ͕ ɹ͋Δɻ ɾશମͱͯ͠ີ݁߹ʹͳ͍ͬͯΔͨΊɺΞʔΩςΫνϟͷมߋ͕ ɹ͔ͳΓΓʹ͍͘ɻ ɾجఈΫϥε͕ԿͰ͔ΜͰ͍ͬͯΔঢ়ଶʹͳͬͯ͠·ͬͯ ɹ͍ͨ(Ұ෦ͷαϒΫϥεͰ͔͠Θͳ͍ॲཧ͋ͬͨΓɻɻɻ)
ܧঝ͔Βίϯϙδγϣϯ ɾΫϥεΛআ ɾUIͷڞ௨෦ΛΧελϜViewΫϥεͱͯ͠Γग़͢ ɾجఈΫϥεͷॲཧɺҰ୴ɺ֤ViewController
Կ͕ྑ͘ͳ͔ͬͨʁ ɾίʔυશମͷݟ௨͕͠Α͘ͳͬͨɻ ɾGenericʹؔ࿈ͨ͠ॲཧΛॻ͖͘͢ͳͬͨɻ ɾमਖ਼ͷࡍʹݟΔ͖είʔϓ͕ڱ·ͬͨɻ ɾҰ࿈ͷViewControllerͷ݁߹͕Լ͕ͬͨ ɹ(ࢠ͕ؔͳ͘ͳͬͨͨΊ)ɻ ɾͨͩ͠ɺશମͱͯ͠ͷίʔυྔ͔ͳΓ૿͑ͨɻɻɻ
ͲΜͳίʔυ͕૿͔͑ͨ ɾಉ͡ػೳ͕ͩશͯͷΫϥεͰར༻͠ͳ͍ίʔυɻ ɹෳͷΫϥε͕ڠௐͯ͠1ͭͷػೳͱͳΔΑ͏ͳίʔυɻ ྫɿRepositoryͷૢ࡞Λߦ͍ɺͦͷ݁Ռͱͯ͠ViewΛߋ৽͢Δ ɾUIViewController͔ΒݺΕΔ͜ͱ͕લఏͱͳ͍ͬͯΔίʔυ ɹ(UIAlertControllerͳͲɻΧελϜViewʹدͤΔ͜ͱ͕Ͱ͖ͳ͍) ɾViewControllerͷͰ͋Δ͖ίʔυɻ ɹ(ViewɺModelɺViewModelͷશͯͱؔ͢Δ)
protocol extensionͷద༻ ɾෳͷViewControllerؒͰͷڞ௨ॲཧͷIFΛprotocolͱͯ͠ఆٛ ྫɿRepositoryΛૢ࡞͠ɺViewʹө͢Δϝιου ɹɹRepositoryͷΠϯελϯε(computed property) ɹɹViewͷΠϯελϯε(computed property) ɾprotocol extensionͰڞ௨ͷৼΔ͍Λ࣮
protocol extensionͷద༻ ɾ֤ViewControllerʹprotocolΛద༻ɻ ɹcomputed propertyʹɺ֤ViewControllerͷΠϯελϯεΛ ɹ͢ →࣮͔Βͯ͠ৼΔ͍Λڞ௨ԽͰ͖ͨʂ
·ͱΊ - ϥΠϒϥϦԽͯ͠ίʔυͷ࠶ར༻ੑΛߴΊͯ - ςετέʔεͷՃʹΑΓɺมߋڧͯ͘͠ - DIͳͲͰ݁߹Λ͘͠ɺ - దͳσβΠϯύλʔϯΛબͯ͠ϓϩδΣΫτͷෳࡶ͞Λݮ ͢Δ͜ͱͰSwift/iOSͷਐԽʹै͘͢͠ͳΔ͔ɻɻɻʁ
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ
ࢀߟ ɾSwinject/Swinject ɹ(https://github.com/Swinject/Swinject)