Skip to content

Instantly share code, notes, and snippets.

@artemnovichkov
Last active December 16, 2019 03:18
Show Gist options
  • Save artemnovichkov/006b5bdc97cfa710e1ab737999a409a1 to your computer and use it in GitHub Desktop.
Save artemnovichkov/006b5bdc97cfa710e1ab737999a409a1 to your computer and use it in GitHub Desktop.
An example of using Xcode Preview for projects without SwiftUI.
final class ViewController: UIViewController {
}
#if canImport(SwiftUI) && DEBUG
import SwiftUI
struct ViewControllerRepresentable: UIViewRepresentable {
func makeUIView(context: Context) -> UIView {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier: "ViewController")
return viewController.view
}
func updateUIView(_ view: UIView, context: Context) {
}
}
@available(iOS 13.0, *)
struct ViewController_Preview: PreviewProvider {
static var previews: some View {
Group {
ViewControllerRepresentable()
.colorScheme(.light)
.previewDisplayName("Light Mode")
ViewControllerRepresentable()
.colorScheme(.dark)
.previewDisplayName("Dark Mode")
}
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment