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
Mobile Programming Optional
Search
yuichiro_takahashi
December 19, 2018
Technology
0
130
Mobile Programming Optional
モバイルプログラミングの授業で使うスライドです
yuichiro_takahashi
December 19, 2018
Tweet
Share
More Decks by yuichiro_takahashi
See All by yuichiro_takahashi
App Clip - in a nutshell
yuichirokato
0
310
巨大な機能を VIPER + MicroViewController でいい感じに実装した話
yuichirokato
1
770
Mobile Programming Protocol Extension
yuichirokato
0
77
Mobile Programming Protocol
yuichirokato
0
79
Mobile Programming enum
yuichirokato
0
160
Mobile Programming Struct
yuichirokato
0
120
Mobile Programming Initializer Beta
yuichirokato
0
120
Mobile Programming Inheritance
yuichirokato
0
140
Mobile Programing Property & Method
yuichirokato
0
160
Other Decks in Technology
See All in Technology
ブラックフライデーで購入したPixel9で、Gemini Nanoを動かしてみた
marchin1989
1
510
freeeにおけるOAuth_OIDCの活用とAuthleteへの移行
terara
1
100
alecthomas/kong はいいぞ / kamakura.go#7
fujiwara3
1
300
新機能VPCリソースエンドポイント機能検証から得られた考察
duelist2020jp
0
210
5分でわかるDuckDB
chanyou0311
10
3.2k
Microsoft Azure全冠になってみた ~アレを使い倒した者が試験を制す!?~/Obtained all Microsoft Azure certifications Those who use "that" to the full will win the exam! ?
yuj1osm
1
110
AIのコンプラは何故しんどい?
shujisado
1
190
サービスでLLMを採用したばっかりに振り回され続けたこの一年のあれやこれや
segavvy
2
360
10分で学ぶKubernetesコンテナセキュリティ/10min-k8s-container-sec
mochizuki875
3
320
10個のフィルタをAXI4-Streamでつなげてみた
marsee101
0
160
小学3年生夏休みの自由研究「夏休みに Copilot で遊んでみた」
taichinakamura
0
140
ゼロから創る横断SREチーム 挑戦と進化の軌跡
rvirus0817
2
260
Featured
See All Featured
How to Ace a Technical Interview
jacobian
276
23k
Unsuck your backbone
ammeep
669
57k
Thoughts on Productivity
jonyablonski
67
4.4k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Building Your Own Lightsaber
phodgson
103
6.1k
Designing Experiences People Love
moore
138
23k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.4k
Site-Speed That Sticks
csswizardry
2
190
The Pragmatic Product Professional
lauravandoore
32
6.3k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Faster Mobile Websites
deanohume
305
30k
Transcript
OPTIONAL TYPE MOBILE PROGRAMMING 19TH DEC
OPTIONAL TYPE?
ςΩετ OPTIONAL TYPE? ▸ Swiftʹසൟʹग़ͯ͘Δ ? ! ϚʔΫͷਖ਼ମ ▸
Swift͚ͩͰͳ͘ϞμϯͳݴޠʹΑ͘ݟΒΕΔ nil (null) Λ҆શʹѻ͏ҝͷػೳ ▸ ී௨ͷ͚ͩͰͳ͘ nil ೖΕΔ͜ͱ͕Ͱ͖ΔίϯςφͷΑ͏ͳͷ ▸ ܕఆٛͷࡍʹඌʹ ? Λ͚ͭΔ͜ͱͰOptional Type ʹͳΔ ▸ SwiftͰOptionalͱͯ͠ఆٛ͞ΕͨมͷΈnilΛೖ͢Δ͜ͱ͕Ͱ͖Δ ▸ Optional TypeʹͳΔͱී௨ͷܕͱͯ͑͠ͳ͍ͷͰҰOptional͔Β σʔλΛऔΓग़͢ඞཁ͕͋Δ
ςΩετ ࣮ࡍͷίʔυ // มͷ߹ var indexOrNil: Int? = 0 //
͜ͷΑ͏ʹॻ͚Δ var optionalNum: Optional<Int> = 10 // ؔͷ߹ func getImage(named: String?) -> UIImage? { // লུ ... } // ͜ΕͰ͖ͳ͍ print("added: \(optionalNum + 10)”) // ͳΜΒ͔ͷํ๏ͰOptional͔ΒΛऔΓग़͢ඞཁ͕͋Δ(ࠓճ!ϚʔΫ) print("added: \(optionalNum! + 10)”)
ͳΜΒ͔ͷํ๏ͬ ͯʁ
OPTIONAL UNWRAP ʹ͍ͭͯ
ςΩετ OPTIONAL UNWRAP? ▸ ίʔυͷྫͰݟͨΑ͏ʹOptional typeҰσʔλΛऔΓ ग़͔ͯ͠Β͏ඞཁ͕͋Δ ▸ ͜ΕΛ unwrap(։ࣔ?)
ͱݺͿ ▸ unwrap͢Δํ๏͍͔ͭ͋͘ΔͷͰঢ়گʹΑ͍͚ͬͯ Δ͜ͱ͕େࣄ
ํ๏1. FORCED UNWRAP
ςΩετ FORCED UNWRAP? ▸ ଟ͜Ε͕Ұ൪͓खܰͳํ๏ ▸ optionalͰఆٛ͞Εͨมͷඌʹ ! ϚʔΫΛ͚ͭΔ͚ͩ ▸
͕ͨͩ͋͠Δ͔nil͔Ͱ͋Δ͔ʹؔΘΒͣڧ੍తʹOptionalΛ unwrapͯ͠͠·͏ ▸ ͦͷҝnilͩͬͨ߹ϓϩάϥϜ͕Ϋϥογϡ͢Δ ▸ ͲΜͳͱ͖͕࣮֬ʹೖ͍ͬͯΔͱ͍͏͜ͱ(ઈରnilʹͳΒͳ͍ ͱ͍͏ࣄ)͕อূͰ͖Δ߹ͷΈ͍·͠ΐ͏
ςΩετ ࣮ࡍͷίʔυ // มͷ߹ var nilNumber: Int? = nil //
͜ͷΑ͏ʹॻ͚Δ var optionalNum: Optional<Int> = 10 //ม optionalNum ͷඌʹ!ϚʔΫΛ͚ͭͯΛऔΓग़͢ print("added: \(optionalNum! + 10)”) //͜ΕΫϥογϡʂ print("added: \(nilNumber! + 10)”)
ํ๏2. NIL COALESCING OPERATOR
ςΩετ NIL COALESCING OPERATOR? ▸ ͪ͜Βඇৗʹ͓खܰͳํ๏͔ͭ҆શ ▸ optionalͰఆٛ͞ΕͨมͷޙΖʹ ?? <defaultValue>
Λͬͭ͘ ͚Δ ▸ ?? ԋࢉࢠ͕͋ΕͦͷΛฦ͠ɺnilͰ͋Εࢦఆͨ͠ defaultValueΛฦ͢ ▸ defaultValue ͑͞༻ҙͰ͖Ε҆શ͔͓ͭखܰʹ Unwrap Ͱ͖Δ ▸ get or elseͱݺΕΔ͜ͱ͋Δ
ςΩετ ࣮ࡍͷίʔυ // มͷ߹ var nilNumber: Int? = nil //
͜ͷΑ͏ʹॻ͚Δ var optionalNum: Optional<Int> = 10 // ม optionalNum ͷޙΖʹ ?? ϚʔΫΛ͚ͭͯΛऔΓग़͢ // ม optionalNum ͕ nil ͩͬͨΒ 0 ʹͳΔ print("added: \((optionalNum ?? 0) + 10)”)
ํ๏3.OPTIONAL BINDING
ςΩετ OPTIONAL BINDING? ▸ ԋࢉࢠΛ͏ํ๏ʹൺΔͱίʔυྔ૿͑Δ͕ͱͯ҆શ ʹѻ͑Δ ▸ if let
guard let, switch Λͬͯ unwrap ͢Δํ๏ ▸ ͦΕͧΕܗҧ͏͕શͯ optional ͷதΛ৽͍͠ఆʹଋ റ(bind)͢Δ͜ͱͰunwrap͢Δ ▸ Ұ൪Α͘͏ํ๏͔
ςΩετ ࣮ࡍͷίʔυ * ͘ͳΔͷͰXcodeͰ