如何在swift中定义类似`UIView <uitableviewdelegate>`(oc代码)的类型?

时间:2017-04-04 13:59:11

标签: ios swift protocols

UIView的对象或UIView的子类,并符合UITableViewDelegate协议。

我需要通用类型而不是特定类型。因此,使用它的开发人员可以自由定义。我们可以这样做的oc代码:

@property (strong) UIView<SomeDelegate> *contentView;

2 个答案:

答案 0 :(得分:1)

我在想你只是在找这样的东西

class MyView : UIView, UITableViewDelegate {

}

您很可能还必须添加UITableViewDatasource协议

答案 1 :(得分:0)

您可以使用Current Class的扩展方法以及委托或数据源的最佳实践:

class MyView : UIView {

}

extension MyView: UITableViewDelegate,UITableViewDataSource
{

}