1

I created one swift project on Xcode 9 using Swift 4. And and some objective c .h and .m files in my swift project by creating.h bridge file.

I am able to call objective c function from swift class but now i want to call swift function from objective c .h and .m file.

But i am not able to call swift function from objective c function

So what are the steps about that?

1

2 Answers 2

1

Importing "<ProductName>-Swift.h" at the top of your objc file should work.

For example:

#import myCuteCat-Swift.h

Also, don't forget @objc to the Swift method/attribute you want to expose.

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

1 Comment

Please can you explian me as details stepwise? Means which productfile? Can you give me example?
1

In order to call a Swift function or property from Objective-C you have to mark it with the @objc keyword. Example:

@objc func myFunc()

7 Comments

Where do i define @objc func in my project?
It’s a keyword. You don’t need to define it. Prepend the function or property with it as I did in my example above.
means directly use my swift function into objective c class. is their no need to import anything in objective c? and how do compiler know if I have same name swift function in my project which function want to call?
Nope. No imports needed. That’s what the bridging header is for. It does that for you.
Why don’t you go try it and see. Try first, ask second.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.