假设我们有一个这样的函数:
import Foundation
public func data(with string:String?) -> Data? {
if let string = string {
return string.data(using: .utf8)
}
return nil
}
现在来用一下:
let data = data(with: "Hello")
编译器发出了红色怒吼:variable used within it's own initial value.
只好这样写了:
let stringData = data(with: "Hello")
这下没问题了。