Created
December 30, 2021 17:23
-
-
Save StanislavK/5b37e7ab115933e2546ab8051219d885 to your computer and use it in GitHub Desktop.
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
import SwiftUI | |
struct GenericUIViewControllerRepresentable<ViewControllerType>: UIViewControllerRepresentable | |
where ViewControllerType: UIViewController { | |
let factory: (Context) -> ViewControllerType | |
func makeUIViewController(context: Context) -> ViewControllerType { | |
factory(context) | |
} | |
func updateUIViewController( | |
_ uiViewController: ViewControllerType, | |
context: Context | |
) {} | |
} |
For old legacy code add:
#if canImport(SwiftUI) && DEBUG
.
.
.
#endif
- also:
#if canImport(SwiftUI) && DEBUG
import SwiftUI
let deviceNames: [String] = [
"iPhone SE",
"iPhone 11 Pro Max"
]
struct ViewController_Preview: PreviewProvider {
static var previews: some View {
ForEach(deviceNames, id: \.self) { deviceName in
GenericUIViewControllerRepresentable { _ in
ViewController()
}
.previewDevice(PreviewDevice(rawValue: deviceName))
.previewDisplayName(deviceName)
}
}
}
#endif
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: