Reference: Http://www.tuicool.com/articles/QZNrErM
Even if you try to use Swift to write iOS programs, you will inevitably encounter some of the algorithms are written in C + + language. Then you can only ask "Niang" or "brother" how to call the C + + algorithm with Swift.
One, c,c++, objective-c,swift What is the relationship, and what is mixed-.-?
1. brother, of course, although objective-c is an object-oriented programming language that expands C, C + + is a common programming language developed on the basis of C language. Swift was launched by Apple intentionally to co-exist with Objective-c on Apple's operating system. But Objective-c has always been raised by Apple, and c,c++ has become so popular because of the Apple company.
2. Mixed compilation-.-powerful, and feel the respect and anticipation of Steve Jobs for the development technician.
3. c,c++, Objective, Swift but like "Gourd Doll" inside seven brothers among the four of the same cattle, seven gourd is the most powerful, but need seven brothers together to receive the demon. Similarly, Swift is the youngest brother, which means Swift is the most powerful. While we are approaching the Darling Swift, we should always review other languages and not forget his brothers.
Two, a little comparison.
1. Swift and Objective-c
We all realize that it is not difficult or troublesome to get swift to call objective-c. As long as you create an OC file in Swift's project, the system will ask you to generate a bridging-header, as long as you import all the OC headers in this bridging-header, You can use Swift's language style to invoke the OC class in swift files.
2. Swift and C + +
C + + is not like objective-c. First of all, we should think of objective-c and C + + can be mixed perfect, and can use STL, method is to change the OC. m file suffix to. mm, and then write a wraper in the OC class, and then call the C + + class inside, encapsulated into A few public ways to do it. Then, using Swift to invoke the Wraper method, you can execute the C + + statement.
Third, IOS OC and Swift mixed
1. Create a swift or OC project: I am here to create the Swift language project, project name Swifttest
2. in the project code directory to create a OC class, select the OC Language, a dialog box, select Yes
3. you will see such a header file in the project.
4 . In this header file, add the. h file of your OC file, and you can invoke the included OC file yourself in any swift file.
5. Next in the project target-"build setting->package under the personality of the following two items
6. then introduce a header file such as "-swift.h" in the. m file of the OC code, such as my project will generate swifttest-swift.h such a header file. Then your. m file will be able to invoke swift files casually.
In fact, if you set the defines Module = yes, Xcode will default to the product Module name-swift.h, a header file that will have the. h information for all your. Swift files under this header file.
[iOS] [Swift]swift