How can I build a Swift Package for iOS over command line?
At time of writing (Feb 16, 2019), a working solution is:
swift build -v \
-Xswiftc "-sdk" \
-Xswiftc "`xcrun --sdk iphonesimulator --show-sdk-path`" \
-Xswiftc "-target" \
-Xswiftc "x86_64-apple-ios13.0-simulator"
This command uses -Xswiftc
to workaround the issue by overriding the sdk from macOS to iphonesimulator.
Strictly we add these flags so developers can work around issues, but they also should report a bug so that we can provide a proper solution for their needs.
Source
So I'm guessing there will be a more elegant solution in the future.
How do you build iOS specific packages using SPM?
I "solved" this by wrapping all my files in #if !os(macOS)
#endif
blocks. So the package builds on a Mac, but it doesn't have any content.
How to use Swift Package Manager(SPM) in cli?
I have followed those steps to solve the problem.
- set git HTTP proxy
git config --global http.proxy http://0.0.0.0:1087
git config --global http.proxy socks5://0.0.0.0:1080
- set ssh proxy for host
Append those lines at the end of ~/.ssh/config
to add a socks5 proxy
Host github.com
ProxyCommand nc -X 5 -x 0.0.0.0:1080 %h %p
- use xcodebuild command to resolve package dependencies
Remember you must add the -scmProvider system
option to force xcodebuild to use system git and git configurations, or it will use the xcode built-in git which will never go through the proxy.
xcodebuild -resolvePackageDependencies -scmProvider system
Some references here:
- Building Swift Packages or Apps that Use Them in Continuous Integration Workflows
How to create and build a swift package
UIKit
is a framework in iOS and won't be accessible.
#if canImport(UIKit)
// Code specific to platforms where UIKit is available
#endif
Related:
- Creating a Swift Package with Xcode
Build error when adding a dependency using Swift Package Manager in Xcode for a Flutter project
I think I might have the fix for you.
Please close your workspace in XCode, and go back and open the .xcodeproj file INSTEAD of the .xcworkspace file.
(/yourApp/ios/Runner.xcodeproj most likely)
When the project is open, in XCode menu bar click File -> Project Settings -> Advanced.
Change the option from LEGACY to XCODE DEFAULT.
Now open the .xcworkspace again and it should work!
Related Topics
What Is Trailing Closure Syntax in Swift
Detect Left and Right Click Events on Nsstatusitem (Swift)
In Swift,There's No Way to Get the Returned Function's Argument Names
Create an Outlet in Storyboard to an Inherited Property
How to Send Push Notifications Without Using Firebase Console
Swiftui: How to Make Entire Shape Recognize Gestures When Stroked
Animating a Navigation Bar Color
Gcd with Static Functions of a Struct
How to Stream Remote Audio in iOS 13? (Swiftui)
Multi-Face Detection in Realitykit
How to Pass Int.Init to a Function in Swift
How to Loop Through an Array from the Second Element in Elegant Way Using Swift
How Should You Handle Closure Arguments for Uialertaction
Custom UI Tableviewcell Selected Backgroundcolor Swift
How to Find the Operator Definition in Swift