Skip to content

Instantly share code, notes, and snippets.

@pteasima
Last active August 18, 2020 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pteasima/98d98db18a86c2c76431100621132bfd to your computer and use it in GitHub Desktop.
Save pteasima/98d98db18a86c2c76431100621132bfd to your computer and use it in GitHub Desktop.
import SwiftUI
#if os(macOS)
import Cocoa
protocol ViewRepresentable: NSViewRepresentable {
func makeView(context: Context) -> NSViewType
func updateView(_ view: NSViewType, context: Context)
}
extension ViewRepresentable {
func makeNSView(context: Context) -> NSViewType {
makeView(context: context)
}
func updateNSView(_ nsView: NSViewType, context: Context) {
updateView(nsView, context: context)
}
}
#endif
#if os(iOS)
import UIKit
protocol ViewRepresentable: UIViewRepresentable {
func makeView(context: Context) -> UIViewType
func updateView(view: UIViewType, context: Context)
}
extension ViewRepresentable {
func makeUIView(context: Context) -> UIViewType {
makeView(context: context)
}
func updateUIView(_ nsView: UIViewType, context: Context) {
updateView(uiView, context: context)
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment