无法在 Swift 中将委托设置为 class

Unable to set the delegate to class in Swift

这是他们的示例函数

[GTMagBarDevice sharedDevice].delegate = self;

我试过在 swift 中重写它

GTMagBarDevice.sharedDevice().delegate = self; 

但是我收到一个错误消息"type view controller does not conform to protocol GTMagBarDeviceDelegate"

有什么想法吗?

更新

我已经实现了所有需要的功能,这就是我正在桥接的 .h 文件中所说的

@protocol GTMagBarDeviceDelegate <NSObject>
@required
- (void)magbarDevice:(GTMagBarDevice*)device accessoryConnected:(BOOL)state;
- (void)magbarDevice:(GTMagBarDevice*)device componentFailed:(int)components;

这就是植入

func magbarDevice(magbarDevice: GTMagBarDevice, accessoryConnected isAccessoryConnected: Bool) {

}

func magbarDevice(magbarDevice: GTMagBarDevice, componentFailed components: Int) {

}

您需要实现您所遵循的协议要求的方法。

看起来你的函数签名不正确。试试这些:

func magbarDevice(device: GTMagBarDevice!, accessoryConnected state: Bool) {

}
func magbarDevice(device: GTMagBarDevice!, componentFailed components: Int32) {

}