-
集合:去重且无序,数组有序列表查看全部
-
min = numbers.minElement() max = numbers.maxElement()查看全部
-
大写的服查看全部
-
闭包可以理解为一个匿名函数,所以 1.不需要函数名 2.不需要有外部参数名 3.闭包的声明最后要加in关键字 4.闭包使用{}包裹查看全部
-
然而3.X中已经不支持if where了,变成用“,”分割了,更加简洁。 swift 3.0 中,似乎第二个解包也需要写上 let 。查看全部
-
最近一句显示视图已改为:XCPlaygroundLiveViewRepresentation.View(showView)查看全部
-
func tier1MailFeeBy(weight:Int) -> Int { return 1 * weight } func tier2MailFeeBy(weight:Int) -> Int { return 3 * weight } func chooseMailFeeCalculationBy(weight: Int) -> (Int) -> Int { return weight <= 10 ? tier1MailFeeBy : tier2MailFeeBy } func feeBy(unitPrice: Int, weight: Int) ->Int { let maiFeeByWeight = chooseMailFeeCalculationBy(weight) return maiFeeByWeight(weight) + unitPrice * weight } var price = 20 var weight = 15 feeBy(price, weight: weight)查看全部
-
import UIKit //默认参数 func sayHelloTo(name: String , withGreetingWord greeting: String = "Hello",mpubctuation: String = "!") -> String {<br> return "\(greeting),\(name)\(mpubctuation)" } sayHelloTo("Playground", withGreetingWord: "Hello")<br> sayHelloTo("bobob") sayHelloTo("imooc", mpubctuation: "!!!") //可变参数 func mean(numbers: Double...) -> Double { var sum: Double = 0 for number in numbers { sum += number } return sum / Double(numbers.count) } mean(1,2) mean(12,13,45) func sayHelloTo1(names: String ... , withGreetingWord greeting: String,mpubctuation: String){ for name in names { print("\(greeting), \(name)\(mpubctuation)") } } sayHelloTo1("A","B","C" , withGreetingWord:"Hi" , mpubctuation: "!!")查看全部
-
//一般第一个参数的外部参数名包含在函数名中;withGreetingWord为外部参数名;greeting为内部参数名 func sayHelloTo( name: String , withGreetingWord greeting: String ) -> String { return "\(name),\(greeting)" } //sayHelloTo("Playground", greeting: "Hello") sayHelloTo("Playground", withGreetingWord: "Hello") //计算乘积 func mutipleOf( num1: Int , and num2: Int) -> Int { return num1 * num2 } mutipleOf(4, and: 2) //如果我们只想显示两个值字段 func mutiply( num1: Int , _ num2: Int) -> Int { return num1 * num2 } mutiply(5, 10)查看全部
-
1.集合无序 2.集合去重 (定义集合,数组转集合,集合基本操作,集合的判断)查看全部
-
集合的特点:唯一不重复 、无序、(查重操作)方法.first指随机取出集合中的一个元素查看全部
-
// 强制解包必须确认不为空 errorCode! if errorCode != nil { code + errorCode! } // 解包并使用,errorCode只限在花括号中 if let unWrapedErrorCode = errorCode { "code"+ unWrapedErrorCode } if let errorCode = errorCode { "code" + errorCode } else { "no error" } // 多个解包 if let errorCode = errorCode , errorMsg = errorMsg { ... } // 多个解包 包含多个条件处理 if let errorCode = errorCode , errorMsg = errorMsg where errorCode =="404" { ... }查看全部
-
errorMsg?.upperCaseString 尝试解包 errorMsg!.upperCaseString 确定解包(确保不为空,否则报错)查看全部
-
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)查看全部
-
简洁语法查看全部
举报
0/150
提交
取消