【发布时间】:2016-08-12 02:44:44
【问题描述】:
我带着这个简单的游乐场来说明我的问题:
import UIKit
protocol MyProtocol {
var foo: Bool { get set }
}
class MyGenericClass<T: UIView where T: MyProtocol>: UIView {}
func checkIfIsMyGenericClass(view: UIView) -> Bool {
return view is MyGenericClass // Generic parameter 'T' could not be inferred
}
我需要帮助来识别 MyGenericClass 的实例。
我的实际代码没那么简单,请不要让我更改MyGenericClass声明。
【问题讨论】:
-
为什么需要这样做?你不能检查一个特定的 T 吗?
-
@jtbandes 我不能,因为我想检查任何扩展
UIView并符合MyProtocol的T