从具有关联类型的任何使用协议推断通用

时间:2017-05-05 12:02:41

标签: swift generics swift-protocols associated-types

我试图让这段代码正常工作

{ (tableview, originalItems, item, indexPath) in

    guard let matchingItem = originalItems.filter({ matching($0, with: item.itemIdentifier) }).first else {

        LogManager.Fatal.log("No item matching identifier : \(item.itemIdentifier)")

        return nil

    }
Some code
}

originalItems[Any],我的功能是

static func matching<T: SectionRowRepresentable>(_ item: T, with identifier: String) -> Bool where T.Identity == AnyItemRepresentable.Identity

如何从T推断Any知道SectionRowRepresentable具有关联类型Identity

的事实
public protocol SectionRowRepresentable: Equatable {

  associatedtype Identity: Hashable

  var itemIdentifier: String { get }

}

0 个答案:

没有答案