Enables SwiftUI live previews for UIKit views and view controllers.
In Xcode 13 or later, select File > Add Packages...
In Xcode 12, select File > Swift Packages > Add Package Dependency...
Add https://github.com/nicoelayda/UIKitLivePreview.git
as the package repository URL.
or
If you have an existing Package.swift
file, add UIKitLivePreview
package to your target's dependencies.
dependencies: [
.package(url: "https://github.com/nicoelayda/UIKitLivePreview.git", .upToNextMajor(from: "1.3.1"))
]
Add UIKitLivePreview
to your Cartfile
.
github "nicoelayda/UIKitLivePreview" ~> 1.3.1
Run carthage update --use-xcframeworks
Drag UIKitLivePreview.xcframework
in Carthage/Build
into your application target's Frameworks, Libraries and Embedded Content.
Add UIKitLivePreview
to your Podfile
.
pod 'UIKitLivePreview', '~> 1.3.1'
Run pod install
Copy the contents of Sources/UIKitLivePreview
to your project.
A prebuilt XCFramework binary is also available
UIKitLivePreview
in your view or view controller.PreviewProvider
.previews
property:
preview()
on it to create a wrapped SwiftUI View
instance.ViewModifier
s to customise the preview. See example below.
final class MyViewController: UIViewController { /* ... */ }
#if DEBUG && canImport(SwiftUI)
import SwiftUI
@available(iOS 13.0, *)
struct MyViewController_Preview: PreviewProvider {
static var previews: some View {
MyViewController()
.preview()
.device(.iPhone11)
.landscape()
}
}
#endif
NOTE: If your project is targeting iOS 12, it is recommended to wrap the PreviewProvider
struct in a #if canImport(SwiftUI)
directive and add the @available(iOS 13.0, *)
attribute to it.
Check out UIKitLivePreview-Examples for a sample project.
MIT. See LICENSE.
link |
Stars: 15 |
Last commit: 2 years ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics