Run SwiftUI preview from SPM Package

后端 未结 2 1019
無奈伤痛
無奈伤痛 2021-01-04 10:39

I am developing a package of Swift Package Manager where SwiftUI views need to be included.

Every SwiftUI view should have a preview.

However, when I try to

2条回答
  •  借酒劲吻你
    2021-01-04 11:15

    In Xcode 12 that has changed. Previews are enabled in Swift Packages. In fact, a lot of changes and new features were added that improve the user and developer experience for SwiftUI library extensions. You can watch this WWDC20 session to learn more.

    To get it to work in the first beta of Xcode 12 you have to create a library Swift Package. Make sure you program can build - and that SwiftUI is imported. Also, remember to add the platforms supported in the package manifest - that are supported by SwiftUI and your package code. In the scheme selector select the library that you want to preview and a device supported by your library. After that enable the canvas the preview should be visible. There are currently some rough corners, but I hope errors and usability will improve on later versions.

提交回复
热议问题