Skip to content

Instantly share code, notes, and snippets.

@xmhafiz
Created April 5, 2021 04:25
Show Gist options
  • Select an option

  • Save xmhafiz/a1fc2c21696f38dc31ebb793a2a75760 to your computer and use it in GitHub Desktop.

Select an option

Save xmhafiz/a1fc2c21696f38dc31ebb793a2a75760 to your computer and use it in GitHub Desktop.
Enable UIViewController Live Preview
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