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.6k
哲学とSwiftの発表
ezura
5
580
アプリが動いたその先へ (iOS アプリ開発編)
ezura
1
950
Blending Kotlin's culture into Swift
ezura
1
1.2k
Other Decks in Programming
See All in Programming
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
6
1.7k
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
610
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
340
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
190
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
230
C++でシェーダを書く
fadis
6
4.1k
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
Featured
See All Featured
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
We Have a Design System, Now What?
morganepeng
50
7.2k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Producing Creativity
orderedlist
PRO
341
39k
Become a Pro
speakerdeck
PRO
25
5k
A designer walks into a library…
pauljervisheath
204
24k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
Ruby is Unlike a Banana
tanoku
97
11k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Side Projects
sachag
452
42k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
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