Created
December 13, 2024 19:13
-
-
Save priore/4368c5c85069c66382006e654832e008 to your computer and use it in GitHub Desktop.
UIKit ViewController SwiftUI Preview sample
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
#if canImport(SwiftUI) && DEBUG | |
import SwiftUI | |
@MainActor | |
fileprivate struct UIViewControllerPreview<T: UIViewController>: UIViewControllerRepresentable { | |
let viewController: T | |
init(_ builder: @escaping () -> T) { viewController = builder() } | |
func makeUIViewController(context: Context) -> T { viewController } | |
func updateUIViewController(_ uiViewController: T, context: Context) { } | |
} | |
@MainActor | |
fileprivate struct LoginViewController_Previews: PreviewProvider { | |
static var previews: some View { | |
UIViewControllerPreview { | |
UIStoryboard(name: "Login", bundle: nil).instantiateViewController(withIdentifier: "login") as UIViewController | |
} | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment