【发布时间】:2021-07-26 10:51:46
【问题描述】:
我想创建一种映射对象的方法。所以我有这样的方法:
func testDecode<T: Decodable>(from: DocumentSnapshot) -> T? {
do {
return try from.data(as: T.self)
} catch {
return nil
}
}
我是这样使用它的:
let test = testDecode(from: document.data) as? TestModel
但我有一个错误:Generic parameter 'T' could not be inferred 无法理解为什么我有这个错误,请给我建议
【问题讨论】:
-
因隐藏错误而被否决。这个函数就是
try?关键字。