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

时间:2015-03-19 00:05:55

标签: objective-c swift delegates

这是他们的示例功能

[GTMagBarDevice sharedDevice].delegate = self;

我尝试像这样快速重写它

GTMagBarDevice.sharedDevice().delegate = self; 

但是我收到错误"类型视图控制器不符合协议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) {

}

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

看起来您的功能签名不正确。请尝试这些:

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

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

}