Search code examples
swiftbuildswiftuiswift-package-manager

SwiftUI project builds successfully for simulators but Product > Archive fails with errors in a Swift package


I created my first Swift package by following this article on medium and added it to a Swift project. I can build and run the project containing the package (and many other packages) on simulators fine, but Product > Archive generates errors in my Swift package. The errors all seem to suggest that SwiftUI has not been imported, when it has.

Here's a snippet of the code with a few of the errors:

import SwiftUI // I AM IMPORTING SWIFTUI!

@available(iOS 14.0, OSX 11.0, *)
public struct MyStruct: View { // ERROR: Cannot find type 'View' in scope
    @State private var destinationValue: Double // ERROR: Unknown attribute 'State'
    @Binding private var value: Double // ERROR: Unknown attribute 'Binding'

Solution

  • Please add supported platforms to your Package.swift.

    This could look like this:

    platforms: [
        .iOS(.v13)
    ]
    

    Bernhard