-
高級。。。。查看全部
-
import UIKit func getMaxAndMinFrom(arr: [Int]) -> (max: Int, min:Int)? { guard arr.count > 0 else { return nil } var maxNum = arr[0] var minNum = arr[0] for num in arr { maxNum = num > maxNum ? num : maxNum minNum = num < minNum ? num : minNum } return (maxNum, minNum) } var scores: [Int]? = [202, 1453, 45, 1230, 882, 10] scores = scores ?? [] var result = getMaxAndMinFrom(scores!) if let result = result { print("max of array is \(result.max)") print("min of array is \(result.min)") }查看全部
-
nil colase對optional 判斷是否為nil 進行不同情況 執(zhí)行不同操作查看全部
-
。。。。查看全部
-
errorMsg?.upperCaseString 嘗試解包 errorMsg!.upperCaseString確定解包查看全部
-
解包 unwrap errorCode! 肯定知道是不空的 非nil.強制解包有風險 if errorCode!=nil{code+errorCode!} if let unwrapedErrorCOoe = errorCode{"code"+ unWrappedErroeCode} if let errorCode = errorCode{"code"+ errorCode} else{"no error}// errorCode只限在花括號中 if let errorCode =errorCode , errorMsg = erroeMsg{}//多個解包 if let errorCode =errorCode , errorMsg = erroeMsg where errorCode =="404"{}//多個解包 包含多個條件處理查看全部
-
這個地方高級..查看全部
-
這點猜到了查看全部
-
這個比OC強多了..查看全部
-
print 這個我好像以前知道 0 0查看全部
-
子集 ,超集.相離的.查看全部
-
亦或//查看全部
-
交集 . 減法查看全部
-
并集//查看全部
-
代替三目運算那個確實強大查看全部
舉報
0/150
提交
取消