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 Zoomin' Challenge
Search
Hiron
May 16, 2020
Programming
0
160
だったら、俺が代わりにやってやる / Swift Zoomin' Challenge
Swift Zoomin' の Fat View Controllerを倒せ! 報告会の発表スライドです。
Hiron
May 16, 2020
Tweet
Share
More Decks by Hiron
See All by Hiron
カンファレンス動画鑑賞会のススメ / Osaka.swift #1
hironytic
0
170
try! Swift Tokyo 2024 参加報告 / try! Swift Tokyo 2024 Report
hironytic
0
400
Swift on Windows ファーストインプレッション / Swift on Windows First Impression
hironytic
0
610
iPadOSDC: Multiple Windows
hironytic
4
3k
SwiftのNeverとボトム型 / Never as a Bottom Type
hironytic
2
810
4000のワーニングと戦え!これは警告だ! / 4000 Warnings
hironytic
2
790
シンボリケート / Ore-con 2018 Summer
hironytic
3
1k
全部iOSにしゃべらせちゃえ! / iOSDC 2018 LT
hironytic
3
1.5k
ペダルのある生活 / The Pedal
hironytic
0
420
Other Decks in Programming
See All in Programming
盆栽転じて家具となる / Bonsai and Furnitures
aereal
0
1.9k
月刊 競技プログラミングをお仕事に役立てるには
terryu16
1
1.2k
“あなた” の開発を支援する AI エージェント Bedrock Engineer / introducing-bedrock-engineer
gawa
4
250
いりゃあせ、PHPカンファレンス名古屋2025 / Welcome to PHP Conference Nagoya 2025
ttskch
1
180
Flatt Security XSS Challenge 解答・解説
flatt_security
0
740
ErdMap: Thinking about a map for Rails applications
makicamel
1
660
最近のVS Codeで気になるニュース 2025/01
74th
1
100
PHPで学ぶプログラミングの教訓 / Lessons in Programming Learned through PHP
nrslib
4
1.1k
ある日突然あなたが管理しているサーバーにDDoSが来たらどうなるでしょう?知ってるようで何も知らなかったDDoS攻撃と対策 #phpcon.2024
akase244
2
7.7k
Beyond ORM
77web
11
1.6k
React 19でお手軽にCSS-in-JSを自作する
yukukotani
5
570
Swiftコンパイラ超入門+async関数の仕組み
shiz
0
180
Featured
See All Featured
Designing for Performance
lara
604
68k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
A Philosophy of Restraint
colly
203
16k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.2k
Side Projects
sachag
452
42k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
The Cost Of JavaScript in 2023
addyosmani
46
7.2k
Fireside Chat
paigeccino
34
3.1k
Building Applications with DynamoDB
mza
93
6.2k
Building Your Own Lightsaber
phodgson
104
6.2k
Transcript
ͩͬͨΒɺԶ͕ ΘΓʹͬͯΔʂ 4XJGU;PPNJOνϟϨϯδʙ'BU7JFX$POUSPMMFSΛͤʂʙ ใࠂձ
"CPVU.F w ͻΖΜʢҰٶߒڭʣ w 5XJUUFS(JU)VC2JJUB 4MJEF4IBSF4QFBLFS%FDL ˠIJSPOZUJD w ಙౡࡏॅ w
ීஈ'BU7JFX$POUSPMMFS ͱઓΘͣʹɺͲ͏͖߹ͬ ͍͔ͯ͘Λߟ͍͑ͯ·͢
Ͱ͖͕͋ͬͨͷ w IUUQTHJUIVCDPNIJSPOZUJDSFWFSTJJPT w ΞʔΩςΫνϟύλʔϯɿ .77. 3FEVY w ༻ϑϨʔϜϫʔΫɿ 6*,JUɺ$PNCJOF
ϦϑΝΫλϦϯάΛ ͲͷΑ͏ʹਐΊ͍͔ͯͬͨ
νϟϨϯδ ͷࣗͷϝϞ w σΟεΫຕΧϯτcountDisks(of:) w σΟεΫຕͷଟ͍ํΛฦ͢sideWithMoreDisks() w σΟεΫΛஔ͚Δ͔Ͳ͏͔ௐΔcanPlaceDisk(_:atX:y:)
w σΟεΫΛஔ͚ΔॴΛฦ͢validMoves(for:) w σΟεΫΛஔ͘placeDisk(_:atX:y:animated:completion:)
νϟϨϯδʙཌ #PBSE7JFX 7JFX $POUSPMMFS ˣ͜ͷ࣌ͷϘʔυ #PBSE ϓϩτίϧ ʢ˞ҙຯͳ͔ͬͨʣ 3FWFSTJ -PHJDT
FYUFOTJPO ˞placeDisk()Ξχϝʔ γϣϯͷΩϟϯηϧॲཧΛ ViewController͕͍࣋ͬͯ ͨΓͯ͠ɺ͍ͼͭͳঢ়ଶ IUUQTHJUIVCDPNIJSPOZUJDSFWFSTJJPTQVMM
ಘΒΕͨͷ w ʮͳΜ͔ͬͨͬͨʯͱ͍͏ຬײ
Ϧόʔγ൫ΛϞσϧͱϏϡʔʹ ͷࣗͷϝϞ BoardView ͍࣋ͬͯΔػೳ 3FWFSTJ-PHJDT ͷػೳ struct CellChange: Hashable {
var x: Int var y: Int var disk: Disk? } struct Board { ... mutating func placeDisk(_ disk: Disk, atX x: Int, y: Int) throws -> [CellChange] { ... } } IUUQTHJUIVCDPNIJSPOZUJDSFWFSTJJPTQVMM
ಘΒΕͨͷ w Ϙʔυͷঢ়ଶͱը໘ΛΓͤͨ w Ϧόʔγͷϧʔϧʹجͮ͘มߋ͔͠ߦ͑ͳ͍҆શ ੑʢྫ͑ͻͬ͘ΓฦΒͳ͍ͱ͜ΖʹσΟεΫΛ ஔ͘͜ͱͰ͖ͳ͍ʣ w 3FWFSTJ-PHJDTͷςετίʔυ
ήʔϜਐߦΛ͍͕ͨ͠ʜ w ͳΜͱͳ͘.77. w ϘʔυҎ֎ͷ6*ͷଘࡏ ΛΕ͍ͯΔ w ਐߦͷྲྀΕ͕ཧͰ͖ͯ ͍ͳ͍ w
ΞχϝʔγϣϯΞϥʔ τ7JFXͷͱߟ ͍͑ͯΔ ͷࣗͷϝϞ
ήʔϜਐߦͷྲྀΕΛཧ ͷࣗͷϝϞ
ը໘ 7JFX ͷೖग़ྗཧ ͷࣗͷϝϞ
ήʔϜͷہ໘͕ঢ়ଶભҠ͢Δͱߟ͑ͨ ͷࣗͷϝϞ
ঢ়ଶભҠͱ͍͑ʜ3FEVY ͷࣗͷϝϞ .PEFM 7JFX 7JFX.PEFM 3FEVY
Ϟσϧͷ෦Λ3FEVY෩ʹ࣮ w ΊͬͪΌࢼߦࡨޡͨ͠ 3FEVYࣝͱ͍͚ͯͬͯͨͩͩͬͨ͠ʢ'MVYܦݧ͋Γʣ
ϑΣʔζͱ͍͏ಠࣗ֓೦ public protocol Reducer { /// ΞΫγϣϯʹԠͯ͡ঢ়ଶΛมߋ͠·͢ɻ /// - Parameters:
/// - state: มߋલͷঢ়ଶͰ͢ɻ /// - action: ঢ়ଶมߋΛཁٻ͢ΔΞΫγϣϯͰ͢ɻ /// - Returns: มߋޙͷঢ়ଶΛฦ͠·͢ɻ static func reduce(state: State, action: Action) -> State } public protocol Phase: Reducer, Hashable, CustomStringConvertible { /// ϑΣʔζछผͰ͢ɻ var kind: PhaseKind { get } /// ผͷϑΣʔζ͔Β͜ͷϑΣʔζʹભҠ͢Δͱ͖ʹݺΕ·͢ɻ /// ඞཁʹԠͯ͡αϯΫΛฦ͢͜ͱ͕Ͱ͖·͢ɻ /// - Parameters: /// - previousPhase: ҎલͷϑΣʔζ͕͞Ε·͢ɻ static func onEnter(previousPhase: AnyPhase) -> Thunk? /// ͜ͷϑΣʔζ͔ΒผͷϑΣʔζʹભҠ͢Δͱ͖ʹݺΕ·͢ɻ /// ඞཁʹԠͯ͡αϯΫΛฦ͢͜ͱ͕Ͱ͖·͢ɻ /// - Parameters: /// - state: ݱࡏͷঢ়ଶͰ͢ɻ /// - nextPhase: ࣍ͷϑΣʔζ͕͞Ε·͢ɻ static func onExit(nextPhase: AnyPhase) -> Thunk? } ͷࣗͷϝϞ
Ϟσϧͷ෦Λ3FEVY෩ʹ࣮ w ΊͬͪΌࢼߦࡨޡͨ͠ 3FEVYࣝͱ͍͚ͯͬͯͨͩͩͬͨ͠ʢ'MVYܦݧ͋Γʣ w ຊՈ3FEVYͷαΠτͱɺؔ࿈ٕज़Λݟͨ͠Γ ‣ IUUQTSFEVYKTPSH ‣
IUUQTHJUIVCDPNSFEVYKTSFEVYUIVOL ‣ IUUQTHJUIVCDPNSFEVYMPPQSFEVYMPPQ w ΊͬͪΌษڧʹͳΓ·ͨ͠ɹʜ͕͋·Γग़དྷʹࣗ৴ͳ͍
Ϟσϧͷ෦ͷ࣮͕ͻͱͱ͓ΓऴΘΓʜ ΄Μͷগ͠ςετίʔυΛॻ͍ͯಈ࡞Λ֬ೝ Γͷςετ͍ͬͨΜอཹͯ͠ɺ7JFX.PEFMͷ࣮ʹ IUUQTHJUIVCDPNIJSPOZUJDSFWFSTJJPTQVMM
7JFX.PEFMΛ࣮ɺͦͯ͠ʜ 7JFX$POUSPMMFSͱଓ IUUQTHJUIVCDPNIJSPOZUJDSFWFSTJJPTQVMM
࣮ࡍʹಈ͔ͤͯ༡Δ
ಾػೳͷര w ஔ͚ͳ͍ͱ͜Ζʹஔ͜͏ͱ͢Δͱ w ίϯϐϡʔλʔ͕উखʹߟ͑ͯஔ͍ ͯ͘ΕΔ w ʮͩͬͨΒɺ ɹԶ͕ΘΓʹͬͯΔʂʯػೳ ʢ˞όάʣ
ϞσϧͷςετΛॆ࣮ͤ͞Δ w ঢ়ଶભҠਤΛॻ ͖ͳ͓ͨ͠ w ͜ΕΛݟͳ͕Β ςετέʔεΛ ࡞ͬͨ ʙͷࣗͷϝϞ
ʮͩͬͨΒɺԶ͕ΘΓʹͬͯΔʯػೳ
.PEFMͱ7JFX.PEFMͱͷࠩ w .PEFMʹ7JFXͷߏΛҙࣝͨ͠4UBUF͍࣋ͨͤͯͳ ͍ʢྫɿλʔϯදࣔউഊදࣔʹ %JTL7JFXΛ͏ͳͲʣ w 7JFX.PEFM7JFXͷߏΛڧ͘ҙࣝͯ͠ɺͳΔͦ͘ͷ ··όΠϯσΟϯάͰ͖ΔΑ͏ʹσʔλΛՃ w 7JFXͱ7JFX.PEFMΛ͚Δҙຯʁ
ˠςετ͕ॻ͚Δ 7JFX.PEFMͷςετΛॻ͍͍ͯͳ͔ͬͨ
ָ͍͠(8Λ ա͢͜͝ͱ͕Ͱ͖·ͨ͠
͝ਗ਼ௌ͋Γ͕ͱ͏͟͝·ͨ͠