简体   繁体   中英

Swift Package issue with SwiftUI and Cannot find type 'View' in scope

I am attempting to create a Swift Package to include some common views that I use. When I try to archive the app, this shows up Cannot find type 'View' in scope . The app runs correctly on device and in simulator. Error occurs wherever View appears in the code that is from the Swift Package.

Example of the view:

import Foundation
import SwiftUI

@available(iOS 13.0, *)
public struct ErrorView: View {
    public var errorText: String?
    
    public var body: some View {
        VStack {
            Image(systemName: "xmark.octagon")
                    .resizable()
                .frame(width: 100, height: 100, alignment: .center)
            Text(errorText!)
        }
        .padding()
        .foregroundColor(.white)
        .background(Color.red)
    }
    public init(errorText: String) {
        self.errorText = errorText
    }
}

I after adding platforms: to the package.swift the issue was resolved.

platforms: [
        .iOS(.v14),
        .macOS(.v11)
    ],

Also changed @available(iOS 13.0, *) to @available(iOS 14, macOS 11.0, *) for helping make sure no other issue come up with the views.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM