-
-
Save yury/0855e4eecf4a8c3d98c9d437ab6c54ef 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 Combine | |
import PlaygroundSupport | |
class Model: ObservableObject { | |
@Published var on: Bool = false | |
} | |
class Thing: NSObject { | |
@ObservedObject var model = Model() | |
} | |
var thing = Thing() | |
struct MyView<T: ObservableObject>: View { | |
@Binding var value: Bool | |
@ObservedObject var with: T | |
var body: some View { | |
Rectangle() | |
.foregroundColor(value ? .blue : .red) | |
.frame(width: 100.0, height: 100.0, alignment: .center) | |
.onTapGesture { | |
self.value.toggle() | |
print(self.value) | |
} | |
} | |
} | |
// Present the view controller in the Live View window | |
PlaygroundPage.current.liveView = UIHostingController(rootView: MyView(value: thing.$model.on, with: thing.model)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment