Error building Swift Package in Xcode


I tried it again in Xcode as this and it worked this time: Create the project with interface: SwiftUI. Add local package. Add package dependency. then import the package in SwiftUI code.

Sorry for the noise

Original Post:

Can project containing Swift Package run on iOS?

I build Swift Package in Xcode: File / New / Package...

Just add an executable module in the Sources directory.

macOS: 12.0.1 (21A559)
Xcode: Version 13.1 (13A1030d)

It has the build error:

unable to resolve product type '' for platform 'iphonesimulator'

duplicate output file '/Users/ljh/Library/Developer/Xcode/DerivedData/MyLibrary-frtazaahnkpgqfensmfvdmoimvjf/Build/Products/Debug-iphonesimulator' on task: CreateUniversalBinary /Users/ljh/Library/Developer/Xcode/DerivedData/MyLibrary-frtazaahnkpgqfensmfvdmoimvjf/Build/Products/Debug-iphonesimulator normal arm64 x86_64 i386

| |____MyApp
| | |____main.swift
| |____MyLibrary
| | |____MyLibrary.swift

$ cat Package.swift 

import PackageDescription

let package = Package(
    name: "MyLibrary",
    products: [
        .library( name: "MyLibrary", targets: ["MyLibrary"]),
        .executable( name: "MyApp", targets: ["MyApp"]),
    dependencies: [
    targets: [
        .target( name: "MyLibrary", dependencies: []),
        .executableTarget( name: "MyApp", dependencies: ["MyLibrary"]),
        .testTarget( name: "MyLibraryTests", dependencies: ["MyLibrary"]),

$ cat Sources/MyApp/main.swift 
import Foundation
//import SwiftUI
import MyLibrary

func main(){
    let a = MyLibrary()

$ cat Sources/MyLibrary/MyLibrary.swift 
public struct MyLibrary {
    public private(set) var text = "Hello, World!"

    public init() {
Terms of Service

Privacy Policy

Cookie Policy