Class with custom delegate

Viewed 381

I am creating a custom delegate in a class and trying to implement the protocol in my controller. But is not working as delegate is nil. This is how I am doing it :

BluetoothOperations.swit

protocol GetWatchCollectedData:NSObjectProtocol {
    func getWatchCollectedData(COMMAND_ID : UInt8, data : NSData)
}

class BluetoothOperations: NSObject{
    var getWatchCollectedData: GetWatchCollectedData?

    func customFunc(){
        getWatchCollectedData.getWatchCollectedData(ID,Data)
    }
}

SomeController.swift

class SomeController: UIViewController {
   let object = BluetoothOperations()

   override func viewDidLoad() {
        super.viewDidLoad()
        object.getWatchCollectedData = self

    }
}

extension SomeController: GetWatchCollectedData{
    func getWatchCollectedData(COMMAND_ID : UInt8, data : NSData){
        print("delegate working.")
    } 
}

I have also tried to make an object of class and assign BluetoothOperations's object. getWatchCollectedData = self in viewDidLoad but didn't work.

Any idea where I am doing it wrong ? Thanks.

2 Answers
Related