OC project embedded in Swift, OC mixed development of Swift

1. Open your current OC project, create a new file -> select the swift file, and define the name yourself.
When creating, Xcode will automatically ask you if you want to create a bridging file, click Create, and a .h file will appear.
The name is in this format: project-name-Briding-Header.h

2. At this time, 2 files appeared.
One is CYTSwiftTest.swift you created and the other is project name-Briding-Header.h
Is that ok?
Answer No.
Next, configure our target

3. Select your project - configure
a .buildSettings->search for defines module->set YES

b. buildSettings - > 搜索 Swift Complier - General - >
You will see the project name-Briding-Header.h that was just automatically generated . See the picture:

Below the bridging file, there is a file with project name - Swift.h
Project name - the role of the Swift.h file: automatically help you find the .swift file you created in this project, so you only need to import this file where you need it, and you don't need to import every file. He will automatically get it for you.
The role of project name-Briding-Header.h : You can put the OC files you need in swift into this .h file. Swift language can be obtained.

4. Compile and run.
5. end







Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324818001&siteId=291194637