1
votes

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. The part developed so far worked. I have added simple protocol in Objective C, which declares just one method:

@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 :

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'

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

1
ObjC int is equivalent to Swift Int32 I believe.dan
Ensure you have implemented all the required methods in MyProtocolDelegatechengsam
You should probably use NSInteger in your protocol method declaration.AdamPro13
Thank you! I have changed it the other way. Made the swift updateCount to accept Int32 as an argument. It works.Marek

1 Answers

0
votes

The swift type Int32 is the correct equivalent for the obj-c int

But imo you should use the the C type aliases, to avoid confusion. In your example it would be

func updateCount(count:CInt)
{
    return
}

take a look at Apple - Interacting with C APIs