0

I'm trying to call a Swift function from an Objective-C class and it's throwing:

No visible @interface for 'TUtils' declares the selector 'run'

TUtils.swift

@objc
public class TUtils: NSObject  {
    
    @objc func run() {
        print("Hello test")
    }
}

Consume.m

#import <RKit/RKit-Swift.h>
    
inline int tempFun () {
    TUtils *obj = [TUtils new];
    [obj run];
    return 0;
}

thanks

0

1 Answer 1

1

Typical issue is that functions need to be public in order to be visible by Objective-C. As docs say:

By default, the generated header contains interfaces for Swift declarations marked with the public or open modifier. If your app target has an Objective-C bridging header, the generated header also includes interfaces marked with the internal modifier.

So try to change your function to

@objc public func run() {

and see if this helps. If it does not, clear and rebuild from scratch. You can also open RKit-Swift.h (by command+click on it) and check how TUtils was declared and which functions Objective-C sees.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks setting public before the function, solved my issue
Great, if you accept the answer, it can be referred by others then. Cheers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.