[英]Property Conforming to Protocol with a UIViewController type in Swift
在Objective-c中,我會這樣聲明
@protocol Protocol1
@end
@property (nonatomic, strong) UIViewController<Protocol1> property1;
如何在Swift中聲明property1?
你可能會做這樣的事情
class YourType: UIViewController, Protocol1 {}
var yourVar: YourType
雖然這是一種駭人聽聞的解決方案...
這可能會更糟,我仍然要添加它
class YourClass<T:UIViewController, Protocol1> {
var property1: T?
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.