在 Swift 任何 iOS 设备的包构建中:在范围内找不到类型 'EdgeInsets'
In Swift package building for Any iOS Device: Cannot find type 'EdgeInsets' in scope
当我构建这个非常简单的 Swift 包时,我得到了这个编译器错误:
/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 {}
尽管您正在为 iOS 设备构建,但您似乎还必须在 Package.swift
文件中明确定义您的平台,以使其不给出这个错误:
let package = Package(
name: "WhosebugLibrary",
platforms: [
.iOS(.v13),
.macOS(.v10_15)
],
//etc.
请注意,在我还执行“清理构建文件夹”之前,仅此一项对我仍然不起作用,此时它已正确编译。
当我构建这个非常简单的 Swift 包时,我得到了这个编译器错误:
/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 {}
尽管您正在为 iOS 设备构建,但您似乎还必须在 Package.swift
文件中明确定义您的平台,以使其不给出这个错误:
let package = Package(
name: "WhosebugLibrary",
platforms: [
.iOS(.v13),
.macOS(.v10_15)
],
//etc.
请注意,在我还执行“清理构建文件夹”之前,仅此一项对我仍然不起作用,此时它已正确编译。