Skip to content

Instantly share code, notes, and snippets.

@b3ll
Created November 13, 2019 07:56
Show Gist options
  • Save b3ll/1e4a4445697492f6bea5ce5259a1063f to your computer and use it in GitHub Desktop.
Save b3ll/1e4a4445697492f6bea5ce5259a1063f to your computer and use it in GitHub Desktop.
//: A UIKit based Playground for presenting user interface
import SwiftUI
import UIKit
import PlaygroundSupport
class Model: ObservableObject {
@Published var on: Bool = false
}
class Thing: NSObject {
@ObservedObject var model = Model()
}
var thing = Thing()
struct MyView: View {
@Binding var on: Bool
var body: some View {
Rectangle()
.foregroundColor(on ? .blue : .red)
.frame(width: 100.0, height: 100.0, alignment: .center)
.onTapGesture {
self.on.toggle()
print(self.on)
}
}
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = UIHostingController<MyView>(rootView: MyView(on: thing.$model.on))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment