Reputation: 36013
How do I deal with code that is intended to run on different targets like iOS, macOS, tvOS, etc., inside a package on Xcode 11?
What I mean is this: I have code that I am trying to convert to a package. This code has storyboards for macOS and for iOS and swift classes to run with these storyboards, or in other words, swift classes to run on macOS and others to run on iOS.
I want to be able to create a package that can be imported on any project, independently if this project is iOS only, mac only or has targets for both architectures.
The big problem is that the package has no targets, where I can assign a file to it.
Apple has this example where they show you can specify platforms.
let package = Package(
name: "MyPackage",
platforms: [
.macOS(.v10_13), .iOS(.v11), .tvOS(.v11),
],
but as expected, their docs do not show how.
How do I do that?
Upvotes: 0
Views: 139
Reputation: 2014
Storyboards and other assets are not currently supported with SwiftPM so you cannot do this with those.
If you have just source code then you can use an #if os(iOS)
/#if os(macOS)
block around all of the contents of your files that are for a specific OS.
You will want to put all the files in the same product in order for consuming modules to just use import TheNameOfYourModule
everywhere instead of having iOS/macOS specific import statements.
Upvotes: 1