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 Closure
Search
yuichiro_takahashi
October 22, 2018
Technology
0
100
Mobile Programming Closure
Mobile Programmingの授業のスライドです
yuichiro_takahashi
October 22, 2018
Tweet
Share
More Decks by yuichiro_takahashi
See All by yuichiro_takahashi
App Clip - in a nutshell
yuichirokato
0
350
巨大な機能を VIPER + MicroViewController でいい感じに実装した話
yuichirokato
1
810
Mobile Programming Protocol Extension
yuichirokato
0
82
Mobile Programming Protocol
yuichirokato
0
86
Mobile Programming enum
yuichirokato
0
170
Mobile Programming Optional
yuichirokato
0
130
Mobile Programming Struct
yuichirokato
0
130
Mobile Programming Initializer Beta
yuichirokato
0
120
Mobile Programming Inheritance
yuichirokato
0
150
Other Decks in Technology
See All in Technology
生成AI開発案件におけるClineの業務活用事例とTips
shinya337
0
160
GeminiとNotebookLMによる金融実務の業務革新
abenben
0
240
整頓のジレンマとの戦い〜Tidy First?で振り返る事業とキャリアの歩み〜/Fighting the tidiness dilemma〜Business and Career Milestones Reflected on in Tidy First?〜
bitkey
0
160
PHP開発者のためのSOLID原則再入門 #phpcon / PHP Conference Japan 2025
shogogg
4
920
5min GuardDuty Extended Threat Detection EKS
takakuni
0
180
Node-REDのFunctionノードでMCPサーバーの実装を試してみた / Node-RED × MCP 勉強会 vol.1
you
PRO
0
120
KubeCon + CloudNativeCon Japan 2025 Recap by CA
ponkio_o
PRO
0
240
MySQL5.6から8.4へ 戦いの記録
kyoshidaxx
1
290
ネットワーク保護はどう変わるのか?re:Inforce 2025最新アップデート解説
tokushun
0
140
監視のこれまでとこれから/sakura monitoring seminar 2025
fujiwara3
11
4k
Oracle Audit Vault and Database Firewall 20 概要
oracle4engineer
PRO
3
1.7k
SpringBoot x TestContainerで実現するポータブル自動結合テスト
demaecan
0
110
Featured
See All Featured
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
130
19k
What's in a price? How to price your products and services
michaelherold
246
12k
Raft: Consensus for Rubyists
vanstee
140
7k
Visualization
eitanlees
146
16k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
138
34k
Facilitating Awesome Meetings
lara
54
6.4k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.4k
The Invisible Side of Design
smashingmag
300
51k
Art, The Web, and Tiny UX
lynnandtonic
299
21k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.4k
Being A Developer After 40
akosma
90
590k
Scaling GitHub
holman
459
140k
Transcript
Ϋϩʔδϟ .PCJMF1SPHSBNNJOH0DU UI
ແ໊ؔ Ϋϩʔδϟ
ແ໊ؔ Ϋϩʔδϟ ͱʁ w ໊લͷ௨Γ໊લͷͳ͍ؔ w ໊લ͖ͭؔͱେ͖͘ҧ͏ͱ͜Ζ w มʹೖΕΒΕΔ w
ͱͯ͠ѻ͑Δͱ͍͏ͱ͜Ζ w ߏจएׯมΘΓ·͢ w ϥϜμࣜͳΜͯݺͼํ
ΫϩʔδϟΫοΩϯά { } w ೋͭͷΛड͚औͬͯ͠߹ΘͤΔؔΛߟ͑·͢ w ·ͣΫϩʔδϟͷ࢝·ΓͰ͋Δ\^Λهड़ ·ͣ͜Εʂ
ΫϩʔδϟΫοΩϯά { (number1: Int, number2: Int) -> Int in }
w ࣍ʹΫϩʔδϟ͕ड͚औΔҾΛઃఆ͍͖ͯ͠·͢ w ࠓճ͠ࢉͷؔͳͷͰҾೋͭʹͳΓ·͢ w ؔͱಉ͡Α͏ʹҾ໊લܕͱ͍͏ܗͰఆٛ͞Ε w ෳ͋Δ߹ΧϯϚͰ۠Γ·͢ Ҿ Ҿ Ҿಉ࢜ΧϯϚͰ۠Δ
ΫϩʔδϟΫοΩϯά w ࣍ʹΓΛܾΊ·͢ w ྫ͑ࠓճ͠ࢉͷؔͳͷͰ*OUܕΛҰͭฦ͠·͢ w Կฦ͢ͷ͕ͳ͍߹লུՄೳͰ͢ w ͪͳΈʹฦΓͱݴͬͨΓ͠·͕͢৭ʑΞϨͳͷͰࠓճΓͱݺͼ·͢ w
ΫϩʔδϟͰΓͷޙʹJOͱ͍͏Ωʔϫʔυ͕ඞཁʹͳΓ·͢ ͜ͷ෦͕Γ { (number1: Int, number2: Int) -> Int in } Εͣʹʂ
ΫϩʔδϟΫοΩϯά { (number1: Int, number2: Int) -> Int in let
result = number1 + number2 return result } w ࠷ޙʹΫϩʔδϟͷதΛهड़͍͖ͯ͠·͢ w Γ͕͋Δؔͷ߹ඞͣ࠷ޙʹ w SFUVSOΛ༻ͯ͠Λฦ͢ඞཁ͕͋Γ·͢ ΓΛฦ͢ ؔͰߦ͏ॲཧ
Ϋϩʔδϟͷݺͼग़͠ w ؔͱಉ༷ʹΫϩʔδϟݺͼग़͞ΕΔ·Ͱ࣮ߦ͞Εͳ͍ w ͦͷͨΊఆٛͨ͠ޙʹඞͣݺͼग़͢ඞཁ͕͋Δ w ΫϩʔδϟΛݺͼग़͢߹جຊతʹҰมʹೖΕΔඞཁ͕͋Δ // Ϋϩʔδϟͷఆٛ let
closure = { (number1: Int, number2: Int) -> Int in let result = number1 + number2 return result } // Ϋϩʔδϟͷݺͼग़͠ let added = closure(10, 10) print("result is: \(added)") // 20
ؔܕҾ ճ
ؔܕҾʁ w ઌ΄Ͳઆ໌ͨ͠ΫϩʔδϟΛҾʹͨ͠ͱ͖ͷ໊લ w Ϋϩʔδϟͱͯ͠ѻ͑ΔͨΊؔͷҾʹ͢͜ͱ ͕Ͱ͖Δ w ܁Γฦ͠ͷ࣌ʹग़͖ͯͨNBQΫϩʔδϟΛҾʹͱΔ ؔͰ͋Δ
ؔܕҾʁ // ΫϩʔδϟΛҾʹؚΉؔఆٛ func calculate(number1: Int, number2: Int, calc: ((Int,
Int) -> Int)) -> Int { return calc(number1, number2) } // ؔݺͼग़͠(ΫϩʔδϟҎ֎ͷҾΛຒΊΔ) calculate(number1: 10, number2: 10, calc:)
ؔܕҾʁ // ΫϩʔδϟΛҾʹؚΉؔఆٛ func calculate(number1: Int, number2: Int, calc: ((Int,
Int) -> Int)) -> Int { return calc(number1, number2) } // ؔݺͼग़͠(Ϋϩʔδϟͷ࢝·ΓͷΧοίΛॻ͍ͯɾɾɾ)͘ calculate(number1: 10, number2: 10, calc: { })
ؔܕҾʁ // ΫϩʔδϟΛҾʹؚΉؔఆٛ func calculate(number1: Int, number2: Int, calc: ((Int,
Int) -> Int)) -> Int { return calc(number1, number2) } // ؔݺͼग़͠(Ҿͷ໊લͱܕͱΓͷܕΛॻ͍ͯɾɾɾɾ) calculate(number1: 10, number2: 10, calc: { (num1: Int, num2: Int) -> Int })
ؔܕҾʁ // ΫϩʔδϟΛҾʹؚΉؔఆٛ func calculate(number1: Int, number2: Int, calc: ((Int,
Int) -> Int)) -> Int { return calc(number1, number2) } // ؔݺͼग़͠(in ΩʔϫʔυΛॻ͍ͯɾɾɾ) calculate(number1: 10, number2: 10, calc: { (num1: Int, num2: Int) -> Int in })
ؔܕҾʁ // ΫϩʔδϟΛҾʹؚΉؔఆٛ func calculate(number1: Int, number2: Int, calc: ((Int,
Int) -> Int)) -> Int { return calc(number1, number2) } // ؔݺͼग़͠(࠷ޙʹॲཧΛॻ͘ɾɾɾ) calculate(number1: 10, number2: 10, calc: { (num1: Int, num2: Int) -> Int in return num1 + num2 })
0I.Z (PPPPPPPPPPPPPPPPPPPPPPPPP
ྲྀੴʹΊΜͲ͍͘͞
Ϋϩʔδϟͷলུه๏
͖ͬ͞ͷྫΛ͏Ұ // ͬͪ͜লུͰ͖ͳ͍͕ɾɾɾ func calculate(number1: Int, number2: Int, calc: ((Int,
Int) -> Int)) -> Int { return calc(number1, number2) } // ͬͪ͜লུ͢Δͱɾɾɾ calculate(number1: 10, number2: 10, calc: { (num1: Int, num2: Int) -> Int return num1 + num2 }) ͜ͷ͍Ϋϩʔδϟ͕͋Δ͡ΌΖʁ
͖ͬ͞ͷྫΛ͏Ұ // ͬͪ͜লུͰ͖ͳ͍͕ɾɾɾ func calculate(number1: Int, number2: Int, calc: ((Int,
Int) -> Int)) -> Int { return calc(number1, number2) } // ͬͪ͜লུ͢Δͱɾɾɾ calculate(number1: 10, number2: 10) { (num1, num2) in return num1 + num2 } ͜ΕΛ͜͏ͯ͠ɾɾɾ
͖ͬ͞ͷྫΛ͏Ұ // ͬͪ͜লུͰ͖ͳ͍͕ɾɾɾ func calculate(number1: Int, number2: Int, calc: ((Int,
Int) -> Int)) -> Int { return calc(number1, number2) } // ͬͪ͜লུ͢Δͱɾɾɾ calculate(number1: 10, number2: 10ʣ{ $0 + $1 } ͜͏͡Όʂ
None
ॱΛͬͯઆ໌͠·͢
Ϋϩʔδϟͷޙஔه๏
Ϋϩʔδϟͷޙஔه๏ w ؔͷҾͷ࠷ޙ͕Ϋϩʔδϟͷ߹ͦͷΫϩʔδϟΛҾ Ϧετͷ֎ʹग़͢͜ͱ͕Ͱ͖·͢ w ͜ΕΛΫϩʔδϟͷޙஔه๏ 5SBJMMJOH$MPTVSF ͱݺͼ· ͢ calculate(number1:
10, number2: 10) { (num1: Int, num2: Int) -> Int in return num1 + num2 } calculate(number1: 10, number2: 10, calc: { (num1: Int, num2: Int) -> Int return num1 + num2 }) #FGPSF "GUFS
Ϋϩʔδϟͷܕͷলུ
Ϋϩʔδϟͷܕͷলུ w 4XJGUʹܕਪ͕͋ΔͨΊΫϩʔδϟͷҾͱΓͷ ܕΛলུͰ͖Δ߹͕͋Γ·͢ calculate(number1: 10, number2: 10) { (num1,
num2) in return num1 + num2 } calculate(number1: 10, number2: 10) { (num1: Int, num2: Int) -> Int in return num1 + num2 } #FGPSF "GUFS
Ϋϩʔδϟͷม໊ͷ লུ
Ϋϩʔδϟͷม໊ͷলུ w Ϋϩʔδϟͷॲཧ͕ߦͰࡁΉ߹มͷ໊લলུ͢Δ͜ͱ͕ Ͱ͖·͢ w ΘΓʹOͱ͍͏දهΛ͍·͢ w Ҿ͕ෳ͋Δ߹ࠨ͔Β ʜͱ͍͏ܗʹͳΓ·͢ w
·ͨɺSFUVSOলུՄೳͰ͢ calculate(number1: 10, number2: 10) { $0 + $1 } calculate(number1: 10, number2: 10) { (num1, num2) in return num1 + num2 } #FGPSF "GUFS