Swift in Qt. Is there any manual or how-to?
-
Hi
http://www.perry.cz/clanky/swift.html
might of interest. -
@mrjj said in Swift in Qt. Is there any manual or how-to?:
Thx ... Is it compatible to *.pro file? Will it be built automatically or I need to add something into *.pro file?
-
@bogong
Hi
Well, most of it is in .cpp / .h files.
However, the bridge part seems to be in the Editor
"Navigate to your project build settings and find the “Swift Compiler – Code Generation” section. "
so im not sure it can just work with only qmake. the Swift compiler must be involved too.
Also, this might only be needed for swift calling c++ code.
( actually, it can only call c code it seems) -
FINALLY!!! Almost 3 years been trying to find solution for using Swift in Qt. For now found the way.
Got developed own solution for it based on:- https://stackoverflow.com/questions/18854750/qmake-extra-compiler-execution-order
- https://forum.qt.io/topic/19308/solved-compiling-fortran-code-with-gfortran-within-a-c-project
- https://github.com/ArboreusSystems/arboreus_examples/tree/master/objective-c/UsingSwift/UsingSwift_v1
This example using QMake. For CMake haven't found proper way yet. For now have this kind of troubles https://developer.apple.com/forums/thread/722012 with project that uses CMake.
How it works briefly:
- Define QMAKE_EXTRA_COMPILERS parameters in *.pro file
- Create bridge header between Swift an Objective-C SWIFT_OBJC_BRIDGING_HEADER and define SWIFT_OBJC_INTERFACE_HEADER_NAME (this interface header will be created automatically by XCode at time of compilation)
- Create wrapper for Objective-C and C++ via Objective-C++ class (*.mm file) and include SWIFT_OBJC_INTERFACE_HEADER_NAME
- Translate Swift data and objects to C++ in Objective-C++ class. This point might be very tricky because you need to create object in C++ that will have the same data that has Swift class. All of it depends on application logic. Try not use complex data structures. Simplify everything that possible when translating it from Swift to Qt, it will make your life happier.
For now issue closed. Trying to find the way to use Swift with CMake in Qt projects. Happy coding. Here the video of how it works in iOS.
-
The solution for using Swift found. Here the published example when you using CMake subdirectories and here
The problem when you using it's like subtarget not solved yet. The Swift code pieces must be in main target. If it's not, you will have this kind of troubles.
If anyone wants to solve troubles with implementing Swift in subtargets you can play with this project
For me all is working pretty good like it's described above.
For me issue totally closed.
Happy coding!