我正在类中创建一个自定义委托并试图在我的控制器中实现该协议。 但是因为委托没有工作,所以没有工作。 这是我正在做它:带自定义代理的类
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'对象是全局对象吗? ,或者显示如何创建实例 –