iOS Developer

Swift中的那些泛型约束

2016-11-15  本文已影响0人  xiAo__Ju

协议泛型约束

protocol ArrayPresenter {
    associatedtype ViewType: UIScrollView
    var listView: ViewType! { set get }

listView的类型约束在了UIScrollView及其子类

Swift2.3方法泛型约束

    func loadMore<T: UIScrollView where T: YourProtocol>(listView: T, indexPath: NSIndexPath) {
        
    }

listView的类型约束在了UIScrollView及其子类,并且遵循YourProtocol

Swift3.0.1方法泛型约束

    func loadMore<T: UIScrollView>(listView: T, indexPath: NSIndexPath) where T: YourProtocol {
        
    }

同Swift2.3方法泛型约束

上一篇 下一篇

猜你喜欢

热点阅读