This is where generics are needed.
@property (nonatomic) UIViewController<UISplitViewDelegate> *viewController;
Assume you want class called 'MyClass" to have a property called 'viewController' with type UIViewController (or subclass) and that conforms UISplitViewDelegate protocol. In Swift your code will look like
class MyClass<T:UIViewController where T:UISplitViewControllerDelegate>:NSObject{
var viewController:T?
override init(){
super.init()
//..
}
// etc..
}
Notice
class MyClass<T:UIViewController where T:UISplitViewControllerDelegate>:NSObject
line. Here you specify a random T type but you also specify you want T to be derived from UIViewController and conform UISplitViewControllerDelegate. This condition will be checked during compilation. And you declare a property in this line
var viewController:T?
and specify its type as T.
And one question left - how to declare variable of type MyClass? I provide a minimum code from a sample project to illustrate more clearly.
class MyClass<T:UIViewController where T:UISplitViewControllerDelegate>:NSObject{
var viewController:T?
override init(){
super.init()
//..
}
// etc..
}
class ViewController: UIViewController,UISplitViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var a=MyClass <ViewController> ()
a.viewController=self
//..
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//..
}
More information here
Good luck with generics.