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
Re: エラーと警告でコードをデザインする
Search
Yuka Ezura
March 22, 2017
Programming
2
950
Re: エラーと警告でコードをデザインする
Yuka Ezura
March 22, 2017
Tweet
Share
More Decks by Yuka Ezura
See All by Yuka Ezura
Mastering share sheet preview
ezura
4
1.3k
SF Symbols
ezura
9
1.2k
気遣いの iOS プログラミング
ezura
11
3.4k
Secret Swift tour
ezura
7
2.8k
Swift Album ver.4.1
ezura
3
1.4k
Swift と Kotlin
ezura
4
2.6k
哲学とSwiftの発表
ezura
5
580
アプリが動いたその先へ (iOS アプリ開発編)
ezura
1
970
Blending Kotlin's culture into Swift
ezura
1
1.2k
Other Decks in Programming
See All in Programming
tidymodelsによるtidyな生存時間解析 / Japan.R2024
dropout009
1
740
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
4.1k
暇に任せてProxmoxコンソール 作ってみました
karugamo
1
720
数十万行のプロジェクトを Scala 2から3に完全移行した
xuwei_k
0
260
RWC 2024 DICOM & ISO/IEC 2022
m_seki
0
200
useSyncExternalStoreを使いまくる
ssssota
6
1k
【re:Growth 2024】 Aurora DSQL をちゃんと話します!
maroon1st
0
770
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
1
360
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
330
今からはじめるAndroidアプリ開発 2024 / DevFest 2024
star_zero
0
1k
快速入門可觀測性
blueswen
0
320
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
190
Featured
See All Featured
Documentation Writing (for coders)
carmenintech
66
4.5k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
The Language of Interfaces
destraynor
154
24k
Building an army of robots
kneath
302
44k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Making Projects Easy
brettharned
116
5.9k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Writing Fast Ruby
sferik
628
61k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
510
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
We Have a Design System, Now What?
morganepeng
51
7.3k
Transcript
Re: ΤϥʔͱܯࠂͰ ίʔυΛσβΠϯ͢Δ 2017/3/22 ezura
ςετ ։ൃମ੍ɾڥ ઃܭࢥɾཧ ݴޠʹΑΔ αϙʔτ j j j j ϜϲεϮϥᩆᕥ
https://speakerdeck.com/ezura/eratojing-gao-de-kodowodezainsuru-chi- tohuang-falselun-wu-qu ΤϥʔͱܯࠂͰίʔυΛσβΠϯ͢Δ NFUIPEṺ΅ᲇͩᘡᔀ͞ᩆ͖ͩͥͺΤ θϸϖΩϰᙉͽݕᒕͫΝ
લఏ struct Object { var name: String var something: Any
func common() { /* do something */ } func method1() { /* do something */ } func method2() { /* do something */ } }
method1 Λ࣮ߦ͔ͯ͠ΒͷΈ method2 Λ࣮ߦՄೳ (ҧΛίϯύΠϧ࣌ʹݕ) Mission1 // OK object.method1().method2() //
Error object.method2()
method1, method2 Λ࣮ߦޙͷ ΠϯελϯεͷΈҾͱͯ͠ड͚औΔؔ (ҧΛίϯύΠϧ࣌ʹݕ) Mission2 // OK accept(object.method1().method2()) //
Error accept(object.method2())
࣮
࣮ͷ֓೦ਤ instance Init state instance State1 instance State2 func method1
func method2
struct Object<State> { var name: String var something: Any func
common() { /* do something */ } }
extension Object where State: Init { func method1() -> Object<State1>
{ /* do something */ } } extension Object where State: State1 { func method2() -> Object<State2> { /* do something */ } } func accept(_ object: Object<State2>) { /* do something */ }
࣮ͷ֓೦ਤ instance Init state instance State1 instance State2 func method1
func method2 Object<Init> Object<State1> Object<State2>
ཧΘ͔ͬͨʂ ࣮ʹམͱ͠ࠐΜͰΈΑ͏
extension Object where State: Init { func method1() -> Object<State2>
{ let object = Object<State2>(…) // Object ͷϓϩύςΟΛҾ͖ܧ͗ return object } }
ܕύϥϝʔλ͕ҧ͏Πϯελϯε (= ҟͳΔܕ) ͷؒͰͲ͏ͬͯσʔλΛҾ͖ܧ͝͏…
Object<Init> ͔Β Object<State1> σʔλΛҾ͖ܧ͙ʹʁʁ new.name = self.name new.something =
self.something struct Container { var name: String var something: Any }
ΩϟετͰ͖ΔΑʂ ۽୩͞Μ
Object<Init> ͔Β Object<State1> extension Object where State: Init {
func method1() -> Object<State2> { let object = unsafeBitCast(self, to: Object<State2>.self) // do something return object } } Object<Init> ͔Β Object<State1> Cast
࣮Ͱ͖ͨʂ ͍উखͲ͏͔ͳʁʁ
let object = Object<Init>(name: "sample", something: "something") <Init> ͷ໌͕ࣔඞཁ… (´ɾωɾʆ)
ίϯύΠϥʹ͑ͯΈΑ͏
extension Object where State: Init { init(name: String, something: Any)
{ self.name = name self.something = something } } State ͕ Init ͷͱ͖ͷΈ ίϯετϥΫλΛએݴ
let object = Object(name: "sample", something: "something") <Init> ͷ໌͕ࣔෆཁ :
͜Ε͕ՄೳͱͳΔ͕݅͋Γ·ׂ͕͢Ѫ͠·͢ (͕݅ἧ͍ͬͯͳ͍߹ɺίϯύΠϧΤϥʔ)
ͱͬͯ៉ྷʹͳΓ·ͨ͠ʂʂ ٩( 'ω' )و
https://gist.github.com/ezura/ e71db2b0471285061f9700809f92f2b1 ίʔυ
ࢀর • ۽୩ͱ៸໘͕ϓϩάϥϛϯάίʔυͷ͔Βௌ͑ͯ͘͜ ΔʹࣖΛָ͚ͯ͠ΉϥδΦ #9, #14 http://mookmookradio.com/a0005/ • where Ͱͷܕਪͷఏএऀͷํͷ
gist https://gist.github.com/tarunon/ d7071689ab55e29bd367a44833687aa3 • ΤϥʔͱܯࠂͰίʔυΛσβΠϯ͢Δ https://speakerdeck.com/ezura/eratojing-gao-de- kodowodezainsuru-chi-tohuang-falselun-wu-qu