Trying to subclass GADRewardBasedVideoAdDelegate on Swift

104 views Asked by At

I am trying to create a singleton class, subclass of GADRewardBasedVideoAdDelegate. Something like this:

import Foundation
import GoogleMobileAds
class MyAdsManager : GADRewardBasedVideoAdDelegate {
    private let id : String = "MY_ADMOB_ID"
    private var selector : (()->Void)?
    static let instance: MyAdsManager = {
        return MyAdsManager()
    }()

    class func getInstance() -> MyAdsManager {
        return instance
    }

    private init() {
        loadVideo()
    }

    //more methods
}

The error message is:

Type 'MyAdsManager' does not conform to protocol 'NSObjectProtocol'

I am not sure if I am doing this correctly, but implementing NSObjectProtocol is not something I am looking for...

Thank you in advance people.

1

There are 1 answers

0
Shehata Gamal On BEST ANSWER

Replace

class MyAdsManager : GADRewardBasedVideoAdDelegate

with

class MyAdsManager : NSObject, GADRewardBasedVideoAdDelegate 

Reason

GADRewardBasedVideoAdDelegate inherits from NSObjectProtocol so you have to implement all methods listed in NSObjectProtocol and since these methods are implemented inside NSObject subclasses so it does the job for you