Chanchal Raj
Chanchal Raj

Reputation: 4336

Importing Swift into Objective-C

When adding .swift files, I don't get a prompt asking for automatically creating a bridge file (may be because I may have pressed NO once). While apple documentation says:

When you import Swift code into Objective-C, you rely on an Xcode-generated header file to expose those files to Objective-C.

It means, you cannot make the MyProjectName-Swift file myself manually like it can be made when importing Objective-C code into a Swift project.

What should I do to bring in the damn prompt that asking for creating a bridging file itself?

P.S. I have only one Target and I want to import only a few .swift files.

Upvotes: 1

Views: 410

Answers (2)

Om Prakash
Om Prakash

Reputation: 9471

First of import #import "MyProductModuleName-Swift.h" class is created automatically.

Replace MyProductModuleName by your xcode project name.

And you can access only those class, delegates and functions which are public in swift class. and delegates should be have prefix @objc.

Upvotes: 0

Chanchal Raj
Chanchal Raj

Reputation: 4336

As per comment by HamG, MyProjectName-Swift is created automatically and it doesn't appear in project files browser. After adding, we can use it directly. You need not put it any path in Build Settings -> Objective-C Bridging Header To use the swift files, just put in import statement as:

#import "MyProductModuleName-Swift.h"

And use any swift class, it should appear in code-completion-list.

The ProjectModuleName can be found in Build Settings-> Product Module Name

Upvotes: 2

Related Questions