クラスにカスタムデリゲートを作成していて、自分のコントローラーでそのプロトコルを実装しようとしています。 デリゲートがnilなので、動作しません。 これは私がそれをやっている方法です:カスタムデリゲートのクラス
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.")
}
}
また、私はクラスのオブジェクトを作成し、BluetoothOperations's object. getWatchCollectedData = self
を割り当てるために試してみましたviewDidLoadでは動作しませんでした。
私はそれが間違っていますか?おかげさまで
BluetoothOperationsのオブジェクトです。 getWatchCollectedData = self –
もそれを試しました。しかし動作しませんでした。 @HarshalValanda –
あなたの 'BluetoothOperations'オブジェクトはグローバルオブジェクトですか? 、またはインスタンス –