Swift Package Manager - Swift 4 syntax
You're missing the tools version specifier in your manifest; add the following as the first line of your Package.swift
:
// swift-tools-version:4.0
By default if that line is omitted, it'll default to manifest version 3 and also compiler version 3. For more information see SE-0152 or Swift Package Manager Manifest API Redesign on swift.org.
Xcode: Using packages in Xcode 14
There is a change in the syntax for local packages, the .package(url: …
syntax that used to work for packages within the project does not work anymore.
With Xcode 14 local packages that do no have their own repo MUST be referred as:
dependencies: [
.package(path: "../MyLibrary"),
]
Now this works just fine in Xcode 14 beta, but if you're going back to the Xcode release version, you'll get numerous errors. To fix those, reset the package caches by calling
File > Packages > Reset Package Caches
I had the same issue in a project with 14 internal packages, some of them dependent on each other, and it runs fine now in both Xcode 13.4 and Xcode 14 beta.
Hope it helps
Specify minimum macOS version for Swift Package Manager with Swift 5
let package = Package(
name: "NAME",
platforms: [
.macOS(.v10_11)
],
products: [
.library(name: "NAME", targets: ["NAME"]),
],
targets: [
.target(name: "NAME"),
]
)
One way to do this is with Deployment Settings in SPM.
How to unit test iOS package with `swift test`?
swift test
only works for macOS testing. It does not support cross builds for iOS.
You do not need an existing Xcode project to use xcodebuild
. Run the command, xcodebuild -list
to initialize a Package.swift
file for testing.
See the example here.
How can I add a local library as a dependency in Swift Package Manager
First: package
dependency can link to other packages only!
It's possible from Swift 5.3 with binaryTarget
but you should build your static library with several needed architectures(arm64, x86_64) and then create XCFramework from them with next command:
xcodebuild -create-xcframework \
-library <path> [-headers <path>] \
[-library <path> [-headers <path>]...] \
-output <path>
e.g.:
xcodebuild -create-xcframework \
-library build/simulators/libMyStaticLib.a \
-library build/devices/libMyStaticLib.a \
-output build/MyStaticLib.xcframework
Then you can create new binary target dependency in your package:
let package = Package(
name: "MyPackage",
...
targets: [
.target(
name: "MyPackage",
dependencies: ["MyStaticLib"]
),
.binaryTarget(name: "MyStaticLib", path: "path/MyStaticLib.xcframework"),
...
]
Note: The path to xcframework starts from the root of the project (same as Package.swift).
Swift Package: Dependent Package can't be found. Remedy?
Facebook SDK for iOS package includes several libraries such as: FacebookCore
, FacebookLogin
, FacebookShare
, FacebookGamingServices
and you should make a dependency to a needed one e.g.:
...
.target(
name: "YourPackage",
dependencies: [.product(name: "FacebookLogin", package: "Facebook")]),
...
Then you can use this library in your code:
import FBSDKLoginKit
func createLoginButton() -> FBLoginButton {
return FBLoginButton()
}
Related Topics
Why Do Some Types (E.G. Float80) Have a Memory Alignment Bigger Than Word Size
Property Cannot Be Declared Public Because Its Type Uses an Internal Type
Convert Swift Dictionary to String
Why Is My Swift Loop Failing with Error "Can't Form Range with End < Start"
Enable + Disable Auto-Layout Constraints
Is Self Captured Within a Nested Function
Accessing a String Enum by Index
Perform a Segue Programmatically
Optionals VS Throwing Functions
Nspredicate with Swift and Core Data
Subclassing VS Extension in Swift
Why Does My Pfanalytics Not Have Trackappopenewithlaunchoptions Function? (iOS Swift)
Interactivepopgesturerecognizer Corrupts Navigation Stack on Root View Controller
Easiest Way to Find Square Root in Swift
Swift: Assigning Function to Variable