Amg91
Amg91

Reputation: 164

Trying to subclass GADRewardBasedVideoAdDelegate on Swift

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.

Upvotes: 1

Views: 104

Answers (1)

Shehata Gamal
Shehata Gamal

Reputation: 100523

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

Upvotes: 1

Related Questions