Hi,
I want to write some reuable code that implements a protocol. It all went fine when it was added in an extension to ViewController, my own subclass of UIViewController, but when I changed the extension to UIViewController, I get the error message:
Instance method 'adViewDidReceiveAd' nearly matches optional requirement 'adViewDidReceiveAd' of protocol 'GADBannerViewDelegate'
against both the methods implemented (with the correct function name), and the code stops getting run.
There was something like this back in XCode 8 (https://stackoverflow.com/questions/39495773/xcode-8-warning-instance-method-nearly-matches-optional-requirement )but they were saying it had been fixed. I am using version 10.0 (10A255).
Here is the code that gives that error message:
extension UIViewController: GADBannerViewDelegate {
// From GADBannerViewDelegate (fully optional protocol)
@objc func adViewDidReceiveAd(_ bannerView: GADBannerView)
{
bannerView.isHidden = false
}
@objc func adView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: GADRequestError)
{
bannerView.isHidden = true
print("AdMob error:", error.localizedDescription)
}
Simply changing UIViewController to ViewController makes it work.
I can't think of any reason that this shouldn't work as is. Can anyone give some certainty on what is up here?
It may be relevant that the protocol used here is defined in Objective-C, and the methods are optional. I have added @objc as an attempt to get it to work, but that made no difference.
TIA
Mark