Created
April 5, 2021 04:25
-
-
Save xmhafiz/a1fc2c21696f38dc31ebb793a2a75760 to your computer and use it in GitHub Desktop.
Enable UIViewController Live Preview
This file contains hidden or 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
| import UIKit | |
| import SwiftUI | |
| extension UIViewController { | |
| // enable preview for UIKit | |
| // source: https://fluffy.es/xcode-previews-uikit/ | |
| @available(iOS 13, *) | |
| private struct Preview: UIViewControllerRepresentable { | |
| // this variable is used for injecting the current view controller | |
| let viewController: UIViewController | |
| func makeUIViewController(context: Context) -> UIViewController { | |
| return viewController | |
| } | |
| func updateUIViewController(_ uiViewController: UIViewController, context: Context) { | |
| // | |
| } | |
| } | |
| @available(iOS 13, *) | |
| func showPreview() -> some View { | |
| Preview(viewController: self) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment