Issue #445

How to add SPM

// swift-tools-version:5.1

import PackageDescription

let package = Package(
    name: "Anchors",
    platforms: [
        .macOS(.v10_11),
        .iOS(.v9),
        .tvOS(.v9)
    ],
    products: [
        .library(
            name: "Anchors",
            targets: ["Anchors"]),
    ],
    targets: [
        .target(
            name: "Anchors",
            dependencies: [],
            path: "Sources"
		),
        .testTarget(
            name: "AnchorsTests",
            dependencies: ["Anchors"]),
    ],
    swiftLanguageVersions: [.v5]
)

To test, swift test to test locally, this should validate Package.swift too

Support multiple platform

To support multiple platform, use platform check

#if canImport(UIKit)
import UIKit
#endif

Use sources in Target

If this property is nil, all valid source files in the target’s path will be included and specified paths are relative to the target path.

A path can be a path to a directory or an individual source file. In case of a directory, the Swift Package Manager searches for valid source files recursively inside it.

.target(
    name: "EasyClosureiOS",
    dependencies: [],
    path: "Sources",
    sources: ["Shared", "iOS"]
)

Error

error: target ‘EasyClosuremacOS’ has sources overlapping sources

How to use

  • SPM packages are at DerivedData/MyApp/SourcePackages/checkouts
  • Delete DerivedData for Xcode to fetch new contents from GitHub
  • Clean build folder as Xcode often caches changes from frameworks

Read more