I'm trying to make UIApplication conform to the following protocol:
protocol URLOpenerProtocol {
func open(_ url: URL, completionHandler: ((Bool) -> Void)?)
}
I've added the following extension:
extension UIApplication: URLOpenerProtocol {}
However, I am getting a conforming error.
Given the UIApplication already has the following method on it:
UIApplication.shared.open(_ url: URL, completionHandler: ((Bool) -> Void)?)
why won't this conform? The two seem to be indentical to me...
Error is as follows:
Type
UIApplicationdoes not conform to protocolURLOpenerProtocol
The actual
openmethod inUIApplicationis declared like this with 3 parameters, and the second and third ones happen to be optional (source):UIApplicationhas no two-parameter method with this signature:It only has the three-parameter one. Therefore, it does not conform to your protocol.
You should add the
optionsparameter into your protocol too, so thatUIApplicationcan conform to it, and I would suggest that you add a protocol extension with the two-parameter version: