Search code examples
swiftcompiler-errorsswift-package-manager

In Swift package building for Any iOS Device: Cannot find type 'EdgeInsets' in scope


When I build this very simple Swift Package, I get this compiler error:

/Users/benleggiero/Desktop/Test/Sources/Test/Test.swift:4:11: error: cannot find type 'EdgeInsets' in scope
extension EdgeInsets: P {}
          ^~~~~~~~~~

Package.swift

// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "Test",
    products: [
        // Products define the executables and libraries a package produces, and make them visible to other packages.
        .library(
            name: "Test",
            targets: ["Test"]),
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages this package depends on.
        .target(
            name: "Test",
            dependencies: []),
        .testTarget(
            name: "TestTests",
            dependencies: ["Test"]),
    ]
)

Sources/Test/Test.swift

import SwiftUI

@available(iOS 13.0, *)
extension EdgeInsets {}

Solution

  • Despite the fact that you're building for an iOS device, it appears that you also have to explicitly define your platform(s) in the Package.swift file in order for it to not give this error:

    let package = Package(
        name: "StackOverflowLibrary",
        platforms: [
            .iOS(.v13),
            .macOS(.v10_15)
            ],
        //etc.
    

    Note that this alone continued to not work for me until I also did a "Clean build folder", at which time it compiled correctly.