// *** 以前 ***
func doubledOld(_ value: Int) -> Int {
return value * 2
}
struct RectangleOld {
var width = 2.0
var height = 3.0
var area: Double { return width * height }
}
// *** 在 5.1 版本中 ***
func doubled(_ value: Int) -> Int { value * 2 }
struct Rectangle {
var width = 2.0
var height = 3.0
var area: Double { width * height }
}
extension Array {
var second: Element? { count > 1 ? self[1] : nil }
}
// 闭包自第一版 Swift 起就是这样;现在函数、
// 属性和下标也遵循同一规则