The latest development of iOS new programming language Swift in the iOS development circle has a large response, at home and abroad there are many tutorials or small examples.
Although the language of Swift is still evolving, and the changes are still relatively large, Apple does not promise that the code will be compatible in the future, but it still does not block the enthusiasm of iOS developers.
Why use Swift to invoke OBJECTIVE-C code
The application written by the Swift language is only just ready to be submitted using the Xcode 6 GM version, and Objective-c has existed for many years as Apple's main development language. There is no mature swift library available, so the current writing application can be said to be inseparable from the invocation of OBJECTIVE-C code.
How to invoke Objective-c code
The solution currently given by Apple is to use a Bridging-header header file to refer to the header file of the OBJECTIVE-C code to be used. where Xcode automatically generated header file names will be in the form of the project name-bridging-header.h. However, this file name format is not necessary and you can define it freely.
Xcode automatic generation scheme
Creating a new Swift project does not automatically generate a header file that invokes Objective-c. However, you can create a new objective-c file in your project, and Xcode will prompt you to generate a corresponding header file to make Swift call. The choice is to automatically generate a header file in the format described above. You can delete the newly created empty objective-c file, leaving only this header file.
Fill in the header file of the Objective-c file or library you want to call later.
customizing scenarios
If you choose to cancel in the previous step, the subsequent new Objective-c file will not be prompted again. Or you want to customize a filename instead of using the Xcode generated file name.
Select Create a new header file with a random filename. For example, it can be Hello.h
After that, in the project-targets, find the Swift Compiler-code generation, here's a key to the objective-c bridging header, where it's worth, to fill in your header file information.
1. You can drag the corresponding header file into the input box that fills in the value
2. Manually fill in the header file path to the input box, such as: hello/hello.h
In this way, you can use the corresponding header file to refer to the OBJECT-C code.