-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Hi! 👋
After testing ContextSDK and integrating with a pet project of mine, I decided to distribute it to the App Store, and faced some issues.
I have an app built in SwiftUI that is being distributed to both iOS and macOS. After integrating ContextSDK, it works fine for iOS, but when attempting to build for macOS, I get this compiler error:
This happens before any evaluation of my app's code. I tried wrapping my code like:
#if os(iOS)
import ContextSDK
#endifBut it still won't compile because apparently Xcodes first looks for those missing files.
One could think that simply adding this to this repo's Package.swift would solve the issue:
let package = Package(
name: "MyiOSOnlyPackage",
platforms: [
.iOS(.v13) // Specify the minimum iOS version
],
…But I don't think it does, unfortunately. As least as of a couple years ago when I last checked, the lack of a specific platform in the platforms array doesn't mean that the missing platform (macOS) isn't available; instead it just means there's no minimum requirement 😅
I think to solve this compiler issue you actually need to compile the ContextSDK source code targeting both iOS and macOS when building the .xcframework. But since it probably makes no sense to have ContextSDK in macOS, you could have compiler flags that either throws compiler errors or runs no-ops (with warning logs maybe?) when building for macOS. You'd probably want to add additional instructions to your docs so that users would wrap their code around compiler directives like I did above (or not, if ContextSDK itself could abstract that away from the user, that'd be preferred 💪)
I hope this makes sense!
If you want to reproduce this locally, it's simple: create a new project on Xcode aiming a "multiplatform app", select SwiftUI as the lifecycle, and build the default boilerplate for macOS. See it succeed. Now add ContextSDK SPM and try to compile for macOS, and it will fail, but if you try for iOS, it will still build.
For now since it's just a pet project I'll just remove the SPM temporarily so I can build and distribute for macOS, and add it back for iOS 😅
Cheers!