SwiftPackage中心のプロジェクトを作りたいが自作のmoduleをimportできない

実現したいこと

iOSDC Japan 2021: Swift Package中心のプロジェクト構成とその実践 / Daiki Matsudateのビデオを参考にSwiftPackage中心のプロジェクトを作りたいと考えています。
動画を見ながら簡単な構成を真似してデフォルトで生成されるContentViewをライブラリの中に移動させて動かしてみようと思ったのですが呼び出せずに困っています

構成

イメージ説明

該当のソースコード

モジュール化したファイル

Swift

1public struct ContentView: View {2 @available(iOS 13.0.0, *)3 public var body: some View {4 VStack {5 Image(systemName: "globe")6 .imageScale(.large)7 .foregroundColor(.accentColor)8 Text("Hello, world!")9 }10 .padding()11 }12 13 public init() {}14}15 16struct ContentView_Previews: PreviewProvider {17 @available(iOS 13.0.0, *)18 static var previews: some View {19 ContentView()20 }21}22 23public struct MyLibrary {24 public private(set) var text = "Hello, World!"25 26 public init() {27 }28}

Package

1let package = Package( 2 name: "MyLibrary", 3 products: [ 4 // Products define the executables and libraries a package produces, and make them visible to other packages. 5 .library( 6 name: "MyLibrary", 7 targets: ["MyLibrary"]), 8 ], 9 dependencies: [ 10 // Dependencies declare other packages that this package depends on. 11 // .package(url: /* package url */, from: "1.0.0"), 12 ], 13 targets: [ 14 // Targets are the basic building blocks of a package. A target can define a module or a test suite. 15 // Targets can depend on other targets in this package, and on products in packages this package depends on. 16 .target( 17 name: "MyLibrary", 18 dependencies: []), 19 .testTarget( 20 name: "MyLibraryTests", 21 dependencies: ["MyLibrary"]), 22 ] 23) 24

呼び出し側

Swift

1import SwiftUI2import MyLibrary3 4@main 5struct SampleProjectApp: App {6 var body: some Scene {7 WindowGroup {8 ContentView() // ここが呼び出せずに困っています9 }10 }11}

Package

1let package = Package( 2 name: "MyLibrary", 3 products: [ 4 // Products define the executables and libraries a package produces, and make them visible to other packages. 5 .library( 6 name: "MyLibrary", 7 targets: ["MyLibrary"]), 8 ], 9 dependencies: [ 10 // Dependencies declare other packages that this package depends on. 11 // .package(url: /* package url */, from: "1.0.0"), 12 ], 13 targets: [ 14 // Targets are the basic building blocks of a package. A target can define a module or a test suite. 15 // Targets can depend on other targets in this package, and on products in packages this package depends on. 16 .target( 17 name: "MyLibrary", 18 dependencies: []), 19 .testTarget( 20 name: "MyLibraryTests", 21 dependencies: ["MyLibrary"]), 22 ] 23) 24

モジュール化する手順が何か間違っているのでしょうか?

コメントを投稿

0 コメント