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
// Before Swift 4.1
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
}
}
// Swift 4.1+
enum SimpleToken: Equatable {
case Name(String)
case Number(Int)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)