-
-
Save yury/0855e4eecf4a8c3d98c9d437ab6c54ef to your computer and use it in GitHub Desktop.
Revisions
-
yury revised this gist
Nov 13, 2019 . 1 changed file with 9 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -9,34 +9,29 @@ 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)) -
yury revised this gist
Nov 13, 2019 . 1 changed file with 8 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,22 +2,28 @@ import SwiftUI import UIKit import Combine import PlaygroundSupport class Model: ObservableObject { @Published var on: Bool = false } class Thing: NSObject, ObservableObject { @ObservedObject var model = Model() var objectWillChange: ObservableObjectPublisher { model.objectWillChange } } var thing = Thing() struct MyView: View { @EnvironmentObject var thing: Thing // Add dependency for the thing @Binding var on: Bool var body: some View { @@ -33,4 +39,4 @@ struct MyView: View { } // Present the view controller in the Live View window PlaygroundPage.current.liveView = UIHostingController(rootView: MyView(on: thing.$model.on).environmentObject(thing)) -
Adam Bell created this gist
Nov 13, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ //: 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))