这个问题在这里已有答案:
- In Swift, how can I declare a variable of a specific type that conforms to one or more protocols? 5个答案
在Objective-C中,您可以在返回值中指定类名和一组协议 . 例如,一个UIScrollViewDelegate的UIViewController:
- (UIViewController<UIScrollViewDelegate> *) viewDelegate;
我找不到在Swift中表达这种方法的方法 . 这样的事情失败了,因为UIViewController不是一个协议:
func viewDelegate() -> protocol<UIViewController, UIScrollViewDelegate>;
1 回答
您可以使用约束创建泛型函数 . 这是否满足您的使用案例?