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
940
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.3k
Secret Swift tour
ezura
7
2.8k
Swift Album ver.4.1
ezura
3
1.4k
Swift と Kotlin
ezura
4
2.5k
哲学とSwiftの発表
ezura
5
570
アプリが動いたその先へ (iOS アプリ開発編)
ezura
1
950
Blending Kotlin's culture into Swift
ezura
1
1.2k
Other Decks in Programming
See All in Programming
GCCのプラグインを作る / I Made a GCC Plugin
shouth
1
150
macOS でできる リアルタイム動画像処理
biacco42
3
1.4k
リリース8年目のサービスの1800個のERBファイルをViewComponentに移行した方法とその結果
katty0324
5
3.5k
cXML という電子商取引の トランザクションを支える プロトコルと向きあっている話
phigasui
3
2.2k
offers_20241022_imakiire.pdf
imakurusu
2
360
推し活としてのrails new/oshikatsu_ha_iizo
sakahukamaki
3
1.6k
Vaporモードを大規模サービスに最速導入して学びを共有する
kazukishimamoto
4
4.3k
Server Driven Compose With Firebase
skydoves
0
390
Vue3の一歩踏み込んだパフォーマンスチューニング2024
hal_spidernight
3
3.1k
Kubernetes for Data Engineers: Building Scalable, Reliable Data Pipelines
sucitw
1
190
推し活の ハイトラフィックに立ち向かう Railsとアーキテクチャ - Kaigi on Rails 2024
falcon8823
6
2.1k
Honoの来た道とこれから
yusukebe
19
3k
Featured
See All Featured
GitHub's CSS Performance
jonrohan
1030
460k
Optimizing for Happiness
mojombo
376
69k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
It's Worth the Effort
3n
183
27k
Git: the NoSQL Database
bkeepers
PRO
425
64k
Fireside Chat
paigeccino
32
3k
Why Our Code Smells
bkeepers
PRO
334
57k
The Pragmatic Product Professional
lauravandoore
31
6.3k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Designing on Purpose - Digital PM Summit 2013
jponch
115
6.9k
Statistics for Hackers
jakevdp
796
220k
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