Created
May 12, 2023 06:01
-
-
Save yoxisem544/21b58a9f3bacfb983b7e94b463aa1f71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if canImport(swiftUI) && DEBUG | |
import UIKit | |
import SwiftUI | |
/// This is a UIKit preview in SwiftUI extension | |
/// With this extension, you will have a `.preview` property to get a swift ui preview view | |
@available(iOS 13.0, *) | |
extension UIViewController { | |
private struct Preview: UIViewControllerRepresentable { | |
let viewController: UIViewController | |
func makeUIViewController(context: Context) -> UIViewController { | |
viewController | |
} | |
func updateUIViewController(_ uiViewController: UIViewController, context: Context) { /* no-op */ } | |
} | |
public var preview: some View { | |
return Preview(viewController: self) | |
} | |
} | |
#endif | |
// MARK: - Example code | |
// MARK: - View Controller | |
// #if canImport(swiftUI) && DEBUG | |
// import SwiftUI | |
// @available(iOS 13.0, *) | |
// struct <#ViewControllerYouWouldLikeToPreview#>_Preview: PreviewProvider { | |
// static var previews: some View { | |
// <#ViewControllerYouWouldLikeToPreview#>().preview | |
// } | |
// } | |
// #endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment