Created
November 13, 2019 07:56
-
-
Save b3ll/1e4a4445697492f6bea5ce5259a1063f 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
//: 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