【发布时间】:2016-10-19 04:04:57
【问题描述】:
我有一个向上冒泡的扩展,
但在 Swift 3 中,
无法推断通用参数“T”
public extension UIResponder
{
public func next<T>() -> T?
{
guard let responder = self.next
else { return nil }
return (responder as? T) ?? responder.next()
}
}
// note - kudos to this excellent post:
// https://blog.veloxdb.com/2016/05/12/bubbling-events-using-uiresponder-in-swift/
在 Swift
class SnapDot:UIView
{
.....
func handleTap(g:UITapGestureRecognizer)
{
(next() as Snap?)?.oneDotWasClicked(self)
}
恐怕不仅(a)我不明白为什么它不会在 Swift 3 中被推断出来,而且(b)即使无休止地尝试随机变化,我也无法让它在 Swift 中工作3 :O
【问题讨论】: