当我尝试运行此代码时,它显示一些错误,如main.swift:13:32: 错误:不推荐使用'.dynamicType'。请改用'type(of:...)' return Neo(obj,tag:String(obj.dynamicType))
import Foundation
var __neo__: [String: Any] = [:]
func Neo<T: Any>(obj: T, tag: String) -> T {
if let ret = __neo__[tag] {
return ret as! T
}
__neo__[tag] = obj
return obj
}
func Neo<T: Any>(obj: T) -> T {
return Neo(obj, tag: String(obj.dynamicType))
}
答案 0 :(得分:0)
这是swift 4的转换代码:
var __neo__: [String: Any] = [:]
func Neo<T: Any>(obj: T, tag: String) -> T {
if let ret = __neo__[tag] {
return ret as! T
}
__neo__[tag] = obj
return obj
}
func Neo<T: Any>(obj: T) -> T {
return Neo(obj: obj, tag: String(describing: type(of: obj)))
}