Posts

Post not yet marked as solved
0 Replies
1.3k Views
Assume you have a working swift package that previews a view see the following question on how to achieve that (https://developer.apple.com/forums/thread/651547?login=true&page=1#617372022). Note make sure your view is in the root folder of the package or live previews will not work. Add a dependency to the package. Example shown below The Problem Currently when you add a swift package manager dependency to a swift package in which you want to view a live preview you receive the following error: The Question How do you view live previews of a SwiftUI view in Xcode 12 Swift Package assuming you have a newly created swift package with another swift package as a dependency? Note: This may be a bug on Apple's part and if I do not see a response in a few days will file a bug report in feedback assistant. Live Preview Diagnostics: build aborted due to an internal error: planningFailed("multiple configured targets of \'SwiftyStoreKit\' are being created for iOS Simulator") SchemeBuildError: Failed to build the scheme "TestPackagePreview" unexpected service error: build aborted due to an internal error: planningFailed("multiple configured targets of \'SwiftyStoreKit\' are being created for iOS Simulator") Build system information: error: unexpected service error: build aborted due to an internal error: planningFailed("multiple configured targets of \'SwiftyStoreKit\' are being created for iOS Simulator") 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: "TestPackagePreview",     platforms: [             .iOS(.v13)         ],     products: [         // Products define the executables and libraries a package produces, and make them visible to other packages.         .library(             name: "TestPackagePreview",             targets: ["TestPackagePreview"]),     ],     dependencies: [         .package(url: "https://github.com/bizz84/SwiftyStoreKit.git", .branch("master"))     ],     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: "TestPackagePreview",             dependencies: ["SwiftyStoreKit"]), // this causes the error in preview, but is needed to use the dependency throughout package.         .testTarget(             name: "TestPackagePreviewTests",             dependencies: ["TestPackagePreview"]),     ] )
Posted Last updated
.
Post marked as solved
3 Replies
4.1k Views
How do you get previews working in a swift package? This talk shows this working, however the following steps do not work. Using Xcode 12 create a new Swift Package Add a simple view with a preview to that swift package (See code below) Attempt to run the preview. See errors Code: #if os(iOS) import SwiftUI @available(iOS 14.0, *) public struct TestView: View {     public init() {             }     public var body: some View {         Text("Hello World")     } } @available(iOS 14.0, *) struct NoDataView_Previews: PreviewProvider {     static var previews: some View {         TestView()     } } #endif Error: Build input file cannot be found:...TestPackagePreview.o' (in targ SchemeBuildError: Failed to build the scheme "TestPackagePreview" Build input file cannot be found: ...TestPackagePreview.o' (in target 'TestPackagePreviewTests' from project 'TestPackagePreview' Link TestPackagePreviewTests (x86_64): error: Build input file cannot be found: ...TestPackagePreview.o' (in target 'TestPackagePreviewTests' from project 'TestPackagePreview') Note I have added "..." in file paths for privacy reasons
Posted Last updated
.