Skip to content

Instantly share code, notes, and snippets.

@prafullakumar
Last active June 23, 2020 16:10
Show Gist options
  • Save prafullakumar/15381b6e22f34c11c1cc96a2df105cc6 to your computer and use it in GitHub Desktop.
Save prafullakumar/15381b6e22f34c11c1cc96a2df105cc6 to your computer and use it in GitHub Desktop.
import SwiftUI
class Brand: ObservableObject {
var name = "Apple"
var type = "Tech"
}
struct ContentView: View {
@StateObject var brand = Brand() //initializing in the struct hence StateObject
var body: some View {
NavigationView {
VStack {
Text(brand.name).padding(.all, 10)
Text(brand.type).padding(.all, 10)
NavigationLink(destination: DetailsView.init(brand: brand)) {
Text("show more")
}
}.navigationTitle("Demo Objects")
}
}
}
struct DetailsView: View {
@ObservedObject var brand: Brand //Observable as Brand is being init from outside
var body: some View {
VStack {
Text(brand.name).padding(.all, 10)
Text(brand.type).padding(.all, 10)
}
}
}
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