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
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
190
PHPUnitしか使ってこなかった 一般PHPerがPestに乗り換えた実録
mashirou1234
0
190
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
380
今年一番支援させていただいたのは認証系サービスでした
satoshi256kbyte
1
260
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
250
バグを見つけた?それAppleに直してもらおう!
uetyo
0
180
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
2
3.7k
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
550
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
930
暇に任せてProxmoxコンソール 作ってみました
karugamo
2
720
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
4
270
create_tableをしただけなのに〜囚われのuuid編〜
daisukeshinoku
0
250
Featured
See All Featured
Building Applications with DynamoDB
mza
91
6.1k
Agile that works and the tools we love
rasmusluckow
328
21k
Code Review Best Practice
trishagee
65
17k
The Pragmatic Product Professional
lauravandoore
32
6.3k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Building an army of robots
kneath
302
44k
Designing Experiences People Love
moore
138
23k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Making the Leap to Tech Lead
cromwellryan
133
9k
Raft: Consensus for Rubyists
vanstee
137
6.7k
A Modern Web Designer's Workflow
chriscoyier
693
190k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.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