it actually prints out "Hello 120!" )Ĭompile and run. Somewhere inside a Swift file you can use the factorial method: print( "Hello \( factorial( 5)) !") Inside the bridging header, simply import the C header file: #include "factorial.h" This is gona be the implementation of the method (factorial.c): #include "factorial.h" Let's create a public header for the C code (factorial.h): #ifndef factorial_h The name of this file is tricky, because it also supports other C family langages, like pure C or C , Objective-C and plus-plus. Next, add a new file and choose the C file template.Īfter you enter the name and check the also create header file box, Xcode will ask you about the Objective-C bridging header file. Fill out the required fields, and of course choose the Swift language. Let's fire up Xcode and start a brand new single view app iOS project. ![]() ![]() This means that you can eaily ship your own system modules, you just have to learn how to use the Swift Package Manager.? Bridging header inside Xcode ![]() From Swift 4 there is native support for wrapping C libraries in Swift system module packages.
0 Comments
Leave a Reply. |