際際滷

際際滷Share a Scribd company logo
Function & Closure
about Swift
谿曙蟲 覲危旧螻牛螻 Mobile-X 蟾
讌蟲 : 覦蠏
2015.1.13
覈谿
 矧(酷顎稼界岳庄看稼)
 譴豌(Nested Function)
 企(Closure)
矧(酷顎稼界岳庄看稼)
   伎 蠍磯レ 蟲 讌豌
 襦蠏碁覦 覃伎 伎  譴 蠍磯
矧(酷顎稼界岳庄看稼)
  蟲煙 企 朱Г 覦螳 蟲 覿覿
朱 蟲焔 
 Swift   func れ襯  蟲
矧(酷顎稼界岳庄看稼)
矧(酷顎稼界岳庄看稼)
 企
矧(酷顎稼界岳庄看稼)
朱Г 企
矧(酷顎稼界岳庄看稼)
覦
矧(酷顎稼界岳庄看稼)
 蟲
矧(酷顎稼界岳庄看稼)
覦螳 襴
矧(酷顎稼界岳庄看稼)
 Swift  讌蟯 蟲覓語朱 襯 蟲 .
 Tuple 伎 螳 蟶朱 螳 return   .
矧(酷顎稼界岳庄看稼)
朱Г : 2螳 String
覦螳 : 1螳 String
矧(酷顎稼界岳庄看稼)
朱Г : 1螳 String , 1螳 Int
覦螳 : None
矧(酷顎稼界岳庄看稼)
朱Г : None
覦螳 : None
矧(酷顎稼界岳庄看稼)
朱Г : 1螳 Int
覦螳 : 2螳 Int
Tuple 伎 螳 螳
覯 return 貅磯.
矧(酷顎稼界岳庄看稼)
 Variadic 朱誤 :  朱Г磯ゼ   螻
螳ロ
 螳  覦一企 襷れ伎 朱Г磯ゼ 覿
矧(酷顎稼界岳庄看稼)
numbers  Int   覦一(Array)
numbers  螳螳  螳
number螳 sum 覲 伎
譴豌 (Nested Function)
 Swift るジ  企  譴豌 螳ロ
 企 譴豌  覦蟾レ(譴蟯 )  
 覲襯   .
 譴豌 語  企 襷 螳ロ覩襦 企
朱  螳ロ
譴豌 (Nested Function)
 FuncA
譴豌  FuncB
(Void -> Int)
retrun a
FuncB碁 FuncA 螳 a
豌襴  
(Void -> Void)
var a = 10
a = a + 10
10
譴豌 (Nested Function)
add() returnAdd() 螳 y
豌襴
譴豌 (Nested Function)
 FuncA
var c : Float
譴豌  FuncB
retrun c + 1
朱Г Void
retrun FuncB
譴豌 ろ蟆郁骸襦
蠏 譴豌襯 覦 蟆曙
(Int -> Int)
1螳 FuncB (Int->Int)  覦
譴豌 (Nested Function)
makeIncremetner() return 螳 語 
increment 覲
AddOne()
譴豌 (Nested Function)
 FuncA
var c : Float
譴豌  FuncB
retrun c + 1
朱Г Void
retrun FuncB
(Int -> Int)
1螳 FuncB (Int->Int)  覦
increment
譴豌 (Nested Function)
 FuncA
譴豌  FuncB
retrun b
朱Г Int a
retrun FuncB
譴豌 ろ蟆郁骸襦
蠏 譴豌襯 覦 蟆曙
(void -> Int)
1螳 FuncB (void->Int)  覦
var b : Float
b += a
makeIncrementor 覦
()->Int 
譴豌 (Nested Function)
 amount朱 Int 朱誤磯ゼ 螳讌
蠏碁Μ螻  企 runningTotal企朱 Int 覲襯 
譴豌 (Nested Function)
incrementor 蟆曙 語螳 讌襷 runntingTotal螻
amount覲襯 覦蟾ロ 谿語^ (貂′)
譴豌 (Nested Function)
runningTotal 覲 語襷
amount襷 讀螳 伎
,runningTotal覲襯 覦蟾ロ襦覿
谿語^ 貂′蠍 覓語
譴豌 (Nested Function)
譴豌 (Nested Function)
 FuncA
 FuncB
朱 1螳 覦一, 1螳 FuncB(Int -> Bool)
retrun Bool(True of false)
 FuncC(FuncB襯 語  朱Г)
(Int->Bool)
Bool螳 覦
(Int->Bool)
retrun Bool(True of false) retrun Bool(True of false)
螳 朱Г郁 
襯  蟆曙
譴豌 (Nested Function)
 FuncB
 FuncC
 FuncA
覦一 譴 10覲企 朱 ture 覃 false
企(Closure)
 貊 企 螻    襴暑 蠍磯 觚
襦
企(Closure)
 貊 企 殊朱 焔 螻 語螳 
朱 覲旧  
 譴豌, 覓企  企 譬襯 譴 朱企.
企(Closure)
朱 襴危
螻 襯 蟲覿 讌
蟲覓 in
Sorted Closure
 sorted function Swift 螻牛 覦一  
 覦一 朱一  朱郁 
 蠍一  覦一 朱一螻 螳  覲
2螳襯 朱磯 螳讌螻 Bool 覦
Sorted Closure
蠍一 覓語 C
Collection(覦一, 襴)襯 詩
Sorted Closure
names String覦一願骸 覦一   螳
(String,String) -> Bool  襯
sorted  朱誤磯 一碁
Sorted Closure
Closure expression syntax : 企
Sorted Closure
sorted Function  sorted closure螳 語襦 一讌蠍 覓語
swift  朱 蠏 螳 sortclosure 朱 蟆 豢襦   蠍 覓語
(String, String) -> Bool 企朱   螳
Sorted Closure
Sorted Closure
???
shorthand argument name,
$0 豌覯讌碁 れ伎 語 $1 覯讌碁 れ伎 語襯 詩覃
企蟆 誤覃 語襯 誤 螳 蟆
Trailing Closure
 企  襷讌襷 朱Г郁 企 朱, 蠏 企 
 蠍碁る 語  蟯  k 蟯碁ゼ 
螻   .
Trailing Closure
FuntionA(A,B,,{Closure express})
FuntionA(A,B,) {Closure express}
Trailing Closure
Thank you
谿瑚 襭
 http://blog.naver.com/seotaji/220129425020
 http://blog.naver.com/sqlpro/220022591074

More Related Content

Function & Closure about Swift