Understanding the Relationship Between Swift and C Language

Asked 2 years ago, Updated 2 years ago, 64 views

We are currently developing an application with Swift.
Therefore, I have a question about the connection between swift and other languages.

I'd like to use the main component analysis in app development, but if you look at the code written in MATLAB or C language, there are hundreds of lines of code.
So, is there any way to use the C language code as it is in the swift language?

For example, if you want to use C language for MATLAB, you can implement it by using the MEX function.
I would like to know if there is such a connection between Swift and C language, and how to do so.

If anyone knows, please let me know.

swift xcode c

2022-09-30 21:09

1 Answers

Since Objective-C is a superset of the C language, if Objective-C can be linked, then C can be linked.Details can be found here at .

The first step is to create an appropriate Objective-C file within Swift's project.Anything in the file is fine.Anyway, if Xcode recognizes that it has an Objective-C file, the dialog "Do you want to configure a bridge header?" appears.

Answer Yes to create a file called <Project Name>-Bridging-Header.h, and add #import<C language header file .h> to the file.

There are linker settings and other restrictions, but you should try to stop here first.


2022-09-30 21:09

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.