Skip to content

Instantly share code, notes, and snippets.

@VAndrJ
Created January 11, 2021 13:19
Show Gist options
  • Save VAndrJ/38276ae660a08a0a423bbd52972418e3 to your computer and use it in GitHub Desktop.
Save VAndrJ/38276ae660a08a0a423bbd52972418e3 to your computer and use it in GitHub Desktop.
Simple extension for Previews of UIView and UIViewController.
#if DEBUG
#if canImport(SwiftUI)
import UIKit
import SwiftUI
@available (iOS 13.0, *)
struct UIViewControllerSwiftUIRepresentable: UIViewControllerRepresentable {
let controller: UIViewController
func makeUIViewController(context: Context) -> UIViewController {
return controller
}
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
}
@available (iOS 13.0, *)
extension UIViewController {
var sRepresentation: some View {
return UIViewControllerSwiftUIRepresentable(controller: self)
}
}
#endif
#endif
#if DEBUG
#if canImport(SwiftUI)
import UIKit
import SwiftUI
@available (iOS 13.0, *)
struct UIViewSwiftUIRepresentable: UIViewRepresentable {
let view: UIView
func makeUIView(context: Context) -> UIView {
return view
}
func updateUIView(_ uiView: UIView, context: Context) {}
}
@available (iOS 13.0, *)
extension UIView {
var sRepresentation: some View {
return UIViewSwiftUIRepresentable(view: self)
}
}
#endif
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment