DontMind
DontMind

Reputation: 99

Get a value from a Swift function in Objective C

I am trying to get a value from a Swift function of a class I made. The Swift file is recognized and properly included in a Objective C project via the MyProdName-Swift.h header. I can instanciate it, but I am not able to get a String from a function.

Swift class:

@objc public class Test : NSObject {

    @objc func getTest () -> NSString{

        return "tested"
    }
}

Objective C class:

Test *test = [Test new];
NSString *testDummy = test.getTest();

In the last line I get "Called object type 'NSString *' is not a function or function pointer".
So obviously I am making some basic mistake, please point me to it.

Upvotes: 3

Views: 347

Answers (1)

Mick MacCallum
Mick MacCallum

Reputation: 130222

You're trying to call the method in Objective C using Swift method call syntax. You should be doing this:

NSString *testDummy = [test getTest];

Upvotes: 7

Related Questions