Created
April 23, 2021 23:53
-
-
Save marlonjames71/20c02f4edaaa290ad523e786450d102a to your computer and use it in GitHub Desktop.
Create previews to use in UIKit
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
struct MyViewControllerClass_Previews: PreviewProvider { | |
static var previews: some View { | |
UIViewControllerPreview { | |
return MyViewControllerClass() | |
} | |
.previewDevice("iPhone SE (2nd generation)") | |
} | |
} | |
import SwiftUI | |
@available(iOS 13, *) | |
struct UIViewControllerPreview<ViewController: UIViewController>: UIViewControllerRepresentable { | |
let viewController: ViewController | |
init(_ builder: @escaping () -> ViewController) { | |
viewController = builder() | |
} | |
func makeUIViewController(context: Context) -> ViewController { viewController } | |
func updateUIViewController(_ uiViewController: ViewController, context: Context) {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Got this from this article: https://www.vadimbulavin.com/effective-auto-layout-programmatically-in-swift/