1、override property | 重写属性
class A {
var property = false
}
class B: A {
override var property: Bool {
get {
return true
}
set {
super.property = newValue
}
}
}
2、make a exact duplicate copy of an array
var arr = [1, 2, 3]
var arrCopy = arr.map { $0.copy() }
3、 test equality of Swift enums with associated values
enum SimpleToken: Equatable {
case Name(String)
case Number(Int)
}
public func ==(lhs: SimpleToken, rhs: SimpleToken) -> Bool {
switch (lhs, rhs) {
case let (.Name(a), .Name(b)),
let (.Number(a), .Number(b)):
return a == b
default:
return false
}
}
enum SimpleToken: Equatable {
case Name(String)
case Number(Int)
}
|