McDonal_11
McDonal_11

Reputation: 4075

Unable to create Bridging header in swift

I am planning to add two files from objective C, [PendulumView.h and PendulumView.m] to swift. But if I try to create bridging header, I am unable to create Bridging header. Xcode doesn't ask me "Would you like to create bridging header?". That dialog box also not appeared. If I proceed and I imported my header file, I am receiving error.

(Command + N) -> iOS -> Source -> Objective-C/Header file. No Bridging header is creating. Automatically, .h or .m file is created.

pendulum_header.h file

#ifndef pendul_test_pendul_Header_h
#define pendul_test_pendul_Header_h

#import "PendulumView.h"

#endif

ViewController file

override func viewDidLoad() {
    super.viewDidLoad()

    var pendul_object = PendulumView() //Error Receiving. Unresolved Identifier PendulumView

}

Screen shot is below:

enter image description here

enter image description here

enter image description here

Upvotes: 1

Views: 944

Answers (2)

McDonal_11
McDonal_11

Reputation: 4075

Mistake is completely my side.

What I did?

  1. Open new project -> Imported that .h and .m file.
  2. Right Click -> New File -> "iOS -> Source -> Objective-C.m"
  3. .m file has been created, but bridging header not created.

What should do?

  1. Open new project
  2. Right Click -> New File -> "iOS -> Source -> Objective-C.m"
  3. Bridging header has been created with .m file.
  4. Then, Import that .h and .m file.

Upvotes: 2

Henny Lee
Henny Lee

Reputation: 3062

Try go to your project settings. In the Build Settings tabs go to the search field and search for bridging. In the following search result you should see: Swift Compiler - Code Generation with a setting for Objective-C Bridging Header. Change the value to your project path (where your project files are stored in) and you should be good to go.

Upvotes: 0

Related Questions