This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//用語言提供的基本語法找出陣列中的奇數和偶數 | |
func test1(arr: [Int]) -> Void { | |
for item in arr { | |
if isOdd(val: item) { | |
print("\(item)") | |
} | |
} | |
} | |
func test2(arr: [Int]) -> Void { | |
for item in arr { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//用語言提供的基本語法 | |
func test1(arr: [Int]) -> Void { | |
for item in arr { | |
if isOdd(val: item) { | |
print("\(item)") | |
} | |
} | |
} | |
func test2(arr: [Int]) -> Void { | |
for item in arr { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ex: 比較 a,b大小 | |
var a = 54 | |
var b = 5 | |
//用function: | |
func compare(val1: Int,val2: Int) -> Bool { | |
return a > b | |
} | |
assert(compare(val1:a,val2:b), "error, a can not larger than b") | |
//用closure: | |
assert(a > b, "error, a can not larger than b") //note: a > b 即為closure,其省略了參數和回傳值 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func B(callback: @escaping (Bool) -> Void) { | |
//step2 | |
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 100) {//this 100s indicates long time task | |
//step 3 | |
callback(true) | |
} | |
} | |
//step1 | |
func B { |
NewerOlder