Last active
December 16, 2019 03:18
-
-
Save artemnovichkov/006b5bdc97cfa710e1ab737999a409a1 to your computer and use it in GitHub Desktop.
An example of using Xcode Preview for projects without SwiftUI.
This file contains 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
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