Skip to content

Instantly share code, notes, and snippets.

@mortenbekditlevsen
Created January 26, 2020 10:13
Show Gist options
  • Save mortenbekditlevsen/22896406b5a627defbbe6747c3e6fa9a to your computer and use it in GitHub Desktop.
Save mortenbekditlevsen/22896406b5a627defbbe6747c3e6fa9a to your computer and use it in GitHub Desktop.
Swift 5.2 only - this will not work in Swift 5.1
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