Reputation: 998
I have UIViewController
in a UINavigationController
. This view controller implement a protocol.
I'm trying to get the first controller of the navigation stack and to cast it :
if let vc = _navigationStack.viewControllers?[0] as? ExplorerInterface {
return vc
}
but I get the error : Cannot downcast from 'AnyObject?' to non-@objc protocol type 'ExplorerInterface'
.
I'm looking for a way to fix this issue without adding the @objc
keyword to my protocol (because this protocol contain swift type like tuples and the @objc
keyword is not compatible with Swift types)
Upvotes: 2
Views: 946
Reputation: 10432
Form Apple Doc:
You can check for protocol conformance only if your protocol is marked with the @objc attribute. Even if you are not interoperating with Objective-C, you need to mark your protocols with the @objc attribute if you want to be able to check for protocol conformance.
Check Swift Protocols
Upvotes: 3