Search code examples
objective-cswiftxcodeobjective-c-swift-bridge

Why can't I access objective-c methods even though file is in bridge?


I have a project with a lot of objective-c code. Now I would like to access that code in my swift files. But for some reason I can't access the objective-c methods even though I can initiate an object of that class.

I have a bridge-file with all the .h files added called projectName-Bridge-Header.h

#import "NumberVerificationViewController.h"

And it's path is added in the build-settings (a side question: I can initiate an object from a class even though the bridge path isn't added to the build-settings. Why is that?):

enter image description here

I can initialize an object from the class, but I can't access the method:

var num = NumberVerificationViewController()
num.numberVerificationCallCompleted

The last line gives error that method does not exist.

I'm new to objective-c so it might be something really simple. Still, it's beyond me.


Solution

  • At first glance, it looks like you might be missing the declaration in the .h file to make the method public.

    NumberVerificationViewController.h
    -(void)numberVerificationCallCompleted:(NSNumber*)responseNumber;
    
    NumberVerificationViewController.m
    -(void)numberVerificationCallCompleted:(NSNumber*)responseNumber {
        ...
    }