-
errorMsg?.upperCaseString 尝试解包 errorMsg!.upperCaseString 确定解包(确保不为空,否则报错)查看全部
-
閉包簡化查看全部
-
初始化查看全部
-
多次解包语法简写。查看全部
-
测试<br> var errorMessage: String? = "Not found"<br> let message3 = errorMessage?? "No error":errorMessage查看全部
-
arr.sort({(a: Int, b: Int) -> Bool in return a > b }) arr.sort({(a:Int, b:Int) -> Bool in return a > b}) arr.sort({a, b in return a > b}) arr.sort({a, b in a > b}) arr.sort({$0 > $1}) arr.sort(>)查看全部
-
func tier1MailFeeBy(weight:Int) -> Int { return 1 * weight } func tier2MailFeeBy(weight:Int) -> Int { return 3 * weight } func feeBy(unitPrice: Int, weight: Int) -> Int { func chooseMailFeeCalculationBy(weight: Int) -> (Int) -> Int { return weight <= 10 ? tier1MailFeeBy : tier2MailFeeBy } let maiFeeByWeight = chooseMailFeeCalculationBy(weight) return maiFeeByWeight(weight) + unitPrice * weight } var price = 20 var weight = 15 feeBy(price, weight: weight)查看全部
-
?? 判断是不是nil ps message ?? “hi”查看全部
-
func getBinaryBy(num: Int) -> String { var res = "" var num = num repeat { res = String(num % 2) + res num /= 2 } while num != 0 return res } getBinaryBy(20) func swapTwoNum(inout num1: Double, inout _ num2: Double) { (num1, num2) = (num2, num1) } var a: Double = 34 var b: Double = 65 swapTwoNum(&a, &b) a b查看全部
-
极简模式,太强大了查看全部
-
func sayHelloTo(name: String, withGreetingString greeting: String = "hello") -> String { return "\(greeting), \(name)" } sayHelloTo("Zhang Qian") func minus(num1: Int, _ num2: Int) -> Int { return num1 - num2 } minus(5, 8) func sayHiTo(names: String ..., withGreetingWords greeting: String) { for name in names { print("\(greeting), \(name)") } } sayHiTo("Steve","Bill","Dell", withGreetingWords: "Good Afternoon")查看全部
-
函数的调用以类似于回调的方式来实现查看全部
-
选择合适的数据结构查看全部
-
卧槽这精简查看全部
-
函数作为返回值的写法查看全部
举报
0/150
提交
取消