In Objective-C, it\'s possible to specify a class conforming to a protocol as a method parameter. For example, I could have a method that only allows a UIViewControlle
You can define foo
as a generic function and use type constraints to require both a class and a protocol.
Swift 4
func foo(vc: T) {
.....
}
Swift 3 (works for Swift 4 also)
func foo(vc:T) where T:UITableViewDataSource {
....
}
Swift 2
func foo(vc: T) {
// access UIViewController property
let view = vc.view
// call UITableViewDataSource method
let sections = vc.numberOfSectionsInTableView?(tableView)
}