Created
January 26, 2020 10:13
-
-
Save mortenbekditlevsen/22896406b5a627defbbe6747c3e6fa9a to your computer and use it in GitHub Desktop.
Swift 5.2 only - this will not work in Swift 5.1
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
import Combine | |
import SwiftUI | |
@propertyWrapper | |
class Observable<T>: ObservableObject { | |
@Published var wrappedValue: T | |
init(wrappedValue: T) { | |
self.wrappedValue = wrappedValue | |
} | |
} | |
struct ContentView: View { | |
@ObservedObject @Observable var point: CGPoint = .zero | |
var body: some View { | |
VStack { | |
Text("Hello, World! \(point.x), \(point.y)") | |
Button("Tap me!") { | |
self.point.x += 2 | |
self.point.y += 3 | |
} | |
} | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment