Last active
June 23, 2020 16:10
-
-
Save prafullakumar/15381b6e22f34c11c1cc96a2df105cc6 to your computer and use it in GitHub Desktop.
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 characters
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