Swift: how to check responds to and assign var declared in protocol as optional

165 Views Asked by At

protocol declaration:

@objc protocol LeftSideMenuViewControllerProtocol {
    var containerShouldPerformContentSegueWithIdentifier:((segueIdentifier: String, object: AnyObject!) -> Void)! {set get}
    optional var containerShouldResizeLeftMenuToValue:((CGFloat) -> Void)! {set get}
}

usage:

override var leftEmbedNavigation: CommonNavigationController? {
        willSet{
            if let nav = newValue {
                if let vc = nav.viewControllers[0] as? LeftSideMenuViewControllerProtocol {
// non optional var, all good
                    vc.containerShouldPerformContentSegueWithIdentifier = {
                        [weak self] (segueIdentifier: String, object: AnyObject!) in

                    }
// optional declaration, cannot assign
                    vc.containerShouldResizeLeftMenuToValue = { [weak self] (newConstraintValue) in

                    }
                }
            }
        }
    }

How do I check var implemented and how do I assign on?

0

There are 0 best solutions below