I am trying to integrate the Stockfish Chess Engine with an app written in Swift. The Stockfish iOS source code is open to all but it was written in Objective-C and the engine is in C++. I don't have issue with objective-c but can not seem to understand how it will work with Swift and is that possible at all. The Stockfish engine has no documentation and it is very difficult for me to grasp how it will be build in a Swift app especially when this is the first time fopr me trying something like that. Other people suggested to me I could try with cocoapods to expose the engine to the swift but I am bit lost here. If anyone has any suggestions for me that would be great. Thank you for your time!
-
Have you read through the official docs on the matter? https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/ What part did you not understand? – Losiowaty May 16 '16 at 12:36
-
Possible duplicate of [Can I have Swift, Objective-C, C and C++ files in the same Xcode project?](http://stackoverflow.com/questions/32541268/can-i-have-swift-objective-c-c-and-c-files-in-the-same-xcode-project) – Caleb May 16 '16 at 12:41
-
Yes I have read but this engine uses C++ and the wrappers explained in the the issue Caleb mentioned I don't understand! But thanks for replying to my question! – Stan May 16 '16 at 14:57
1 Answers
What you really want here is a Swift implementation of the Universal Chess Interface protocol so that any compliant engine could be packaged up with CocoaPods (or Carthage, or SPM, ...) and dropped into any compliant Swift app. That's probably what the people who suggested you try with CocoaPods were thinking.
For the less ambitious task of just getting some Objective-C code linking with Swift, yes that is absolutely possible, you need what's called a "Bridging Header" to expose the Objective-C code to Swift. The complete details are in a free book you can download to iBooks:
Using Swift with Cocoa and Objective-C
This documentation is also online at Apple, here's a direct link to the immediately relevant part:
To import a set of Objective-C files in the same app target as your Swift code, you rely on an Objective-C bridging header to expose those files to Swift. Xcode offers to create this header file when you add a Swift file to an existing Objective-C app, or an Objective-C file to an existing Swift app...
This process generally Just Works™. If not, search for "bridging header" and you should find lots of appropriate discussion!

- 4,744
- 1
- 27
- 37
-
Thanks alexcurylo I am very new in app development and still have not learnt it all! Thanks for your suggestion, I will try and search for any help with UCI implementation! – Stan May 16 '16 at 15:02