[英]Swift ViewController, objective C protocol, Type 'ViewController' does not conform to protocol 'MyProtocolDelegate'
I am working on mixed project which has swift ViewController, Uses C++ code and objective C Class in the role of wrapper for C++ classes. 我正在研究混合项目,它具有swift ViewController,使用C ++代码和目标C类作为C ++类包装器的角色。 The part developed so far worked.
到目前为止开发的部分工作。 I have added simple protocol in Objective C, which declares just one method:
我在Objective C中添加了简单的协议,它只声明了一个方法:
@protocol MyProtocolDelegate <NSObject>
- (void)updateCount:(int)count;
@end
@interface CvVideoCameraWrapper : NSObject
@property (weak,nonatomic) id <MyProtocolDelegate> delegate;
//remaining of my interface
@end
In the swift code I added MyProtocolDelegate to other protocols ViewController complies to and added : 在swift代码中,我将MyProtocolDelegate添加到ViewController遵守并添加的其他协议:
class ViewController: UIViewController, CvVideoCameraDelegate, UITextFieldDelegate, MyProtocolDelegate{
func updateCount(count:Int)
{
return
}
override func viewDidLoad() {
super.viewDidLoad()
self.typedName.delegate = self // this one works
self.videoCameraWrapper.delegate = self
// remaining of my viewDidLoad
}
//remaining of my ViewController
}
Compiler shows error: Type 'ViewController' does not conform to protocol 'MyProtocolDelegate' 编译器显示错误:类型'ViewController'不符合协议'MyProtocolDelegate'
I don't know it the delegate method signature declared in objective C and swift match, if type int in objective C and Int in swift are the same, but I understand that swift does the bridging and my other interaction of swift, objective C and C++ works Please point out what is wrong with this protocol use 我不知道在Objective C和swift匹配中声明的委托方法签名,如果在Objective C中的int类型和swift中的int是相同的,但是我知道swift做了swift和我的其他快速,客观的C和C ++工作请指出此协议使用有什么问题
The swift type Int32 is the correct equivalent for the obj-c int swift类型Int32是obj-c int的正确等价物
But imo you should use the the C type aliases, to avoid confusion. 但是你应该使用C类型的别名,以避免混淆。 In your example it would be
在你的例子中它将是
func updateCount(count:CInt)
{
return
}
take a look at Apple - Interacting with C APIs 看看Apple - 与C API交互
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.