I have a protocol, and I\'d like to have a variable of type UIViewController implementing mu protocol. If I try to do something like:
var delegate:UIViewCon
You cannot declare variable type like that in Swift.
The easiest way to solve your problem is adding UIViewController
methods/properties to BouncingMenuDelegate
requirement:
@objc protocol BouncingMenuDelegate {
// Delegate methods
func boudcingMenu(bouncingMenu:BouncingMenu, didSelectItemAtIndex index:Int)
// required methods/properties from UIViewController
var view:UIView { get }
var navigationController:UINavigationController? { get }
func presentViewController(viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)?)
}
class BouncingMenu:UIView {
weak var delegate:BouningMenuDelegate?
}
If the class implements a protocol you don't care about which class it actually is. This should work:
var delegate: BouncingMenuDelegate?