Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

Problems with FIT SDK in an Xcode Swift Project

Rank

Total Posts: 6

Joined 2015-03-13

PM

So, I've been trying to integrate libFitSdkCppiOS.a in a fairly simple Swift-based project in Xcode 8.3 with little (basically no) success. The problem comes up at compile time, where (with a simple Bridging Header) I get an error indicating that an include from within what should be standard c lib (eg, <string>, <map>, etc.) is not found.

Clearly, a configuration management issue but one that I haven't been able to solve for a day now.

All of the example projects compile fine on their own. I'm able to run them on their own. The problem arises when I integrate the library and some simple example file (eg, ActivityExample.h) and reference it in my bridging header.

When I build, I get errors complaining that the files such as <vector> or <map> can't be found.

What I think is going on is that the compiler is (for some reason) not using libstd at this stage. Why this is, I don't know. I'm somewhat comfortable around Xcode, but this is tipping into the Dark Arts.

Anyone else trying to integrate the FIT SDK into a Swift project with Xcode?

Julian

UPDATE #1: I've made a screenflow showing the problem: https://vimeo.com/205082135

UPDATE #2: Stack Overflow is questioning whether it's even possible to build with a CPP static library: http://stackoverflow.com/questions/42383838/building-swift-objective-c-and-a-static-c-library-together
     
RankRank

Total Posts: 34

Joined 2013-01-28

PM

Hello Julian,

I am going to see if I can track down your problem today with the Objective-C code. I know of a few companies that had integrated it into their applications using the sample apps as reference. I also realize that Swift is the language of choice for most iOS developers and I will investigate the feasability of adding that in the future (but it won't be in the immediate near-term).

The reason the Objective-C library was created was to handle the fact that the native C and C++ code will not handle the file I/O properly in the iOS environment. The Objective-C library wraps the C++ code but handles the File I/O in a way that the iOS frameworks allow.

I will take a look at your vimeo link as well and see if anything sticks out at me.

-Evan      
Rank

Total Posts: 6

Joined 2015-03-13

PM

Thank you Evan. I really appreciate that effort.

I'm curious if the FitGen.exe will ever be able to autogenerate Swift as well — I see that you just provide the executable but not the source. I would be willing to help contribute to the effort to create the Swift autogenerated code, just so you know.

Just to point out that the problem appears to be with the libstdc++ types that are standard in that world (<string>, <map>, <vector>) but are likely replaceable in Swift by String, Array and Dictionary (or NSString, NSArray, NSDictionary).      
RankRank

Total Posts: 34

Joined 2013-01-28

PM

Julian,

I watched your Vimeo and saw the same problem as you. Luckily I have found a workaround to allow you to develop in swift.

Here is what I propose:
1. Implement your FIT Handling in Objective-C (like I have done with sample Activity, Monitoring and Settings objects).
2. Create a class/manager in Objective-C that only exposes objective-C methods and calls all of your FIT file handling code. Do not expose C++ to Swift (as you saw it cannot include std:map, or std:vector which is required directly in fit).
3. Import only your Objective-C interface class into swift using the Bridging Header. (i.e. don't include any c++ files directly).

This will allow you to develop most of your app in swift and just file FIT file handling in Objective-C.

I hope this helps.

-Evan      
Rank

Total Posts: 6

Joined 2015-03-13

PM

Evan

Thank you! I'll try this procedure this afternoon.

Were you able to implement this in an Xcode project you'd be willing to share? Just as a baseline so I can compare the results of my own attempt?

Julian      
RankRank

Total Posts: 34

Joined 2013-01-28

PM

Julian,

I am no swift expert so I can't say i fully worked through the example. But i just copied as you were doing in your Vimeo link. I created a new Objective-C class that exposes one public static method that would call the underlying FIT classes. The Bridging-Header included the Objective-C class just fine and didn't have any errors so I am assuming it should work fine with your Swift code, if not send me a PM and we will see if we can figure it out together.

-Evan      
Rank

Total Posts: 6

Joined 2015-03-13

PM

Evan

Thank you again. Got it sorted. For those who may come across this in the future, I created a trivial derivative of the exampleios project here: https://github.com/bleeckerj/fit-sdk-with-swift

Julian      
Rank

Total Posts: 5

Joined 2020-09-08

PM

bleeckerj - 24 February 2017 05:04 PM
Evan

Thank you again. Got it sorted. For those who may come across this in the future, I created a trivial derivative of the exampleios project here: https://github.com/bleeckerj/fit-sdk-with-swift

Julian


Could you please check this and help me how to run it in new xcode 11 or later ?