-
-
Save jeria93/02ee0144eb06be7af18a4c29efef2f68 to your computer and use it in GitHub Desktop.
Trying to pass data through State data and NavigationLinks
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 Foundation | |
struct Laundry: Identifiable, Codable{ | |
let id = UUID() | |
var image: String | |
var description: String | |
var summary: String | |
var tumbling: [Tumbling] | |
} | |
import Foundation | |
struct Tumbling: Identifiable, Codable { | |
let id = UUID() | |
var image: String | |
var description: String | |
var summary: String | |
} | |
import SwiftUI | |
struct LaundryList: View { | |
@Binding var laundry: [Laundry] | |
var body: some View { | |
VStack { | |
List(laundry) { item in | |
WashListRow(laundry: item) | |
} | |
} | |
} | |
} | |
#Preview { | |
LaundryList(laundry: Binding.constant([Laundry]())) | |
} | |
import SwiftUI | |
struct TumblingList: View { | |
var tumbling: [Tumbling] | |
var body: some View { | |
VStack { | |
List(tumbling) { item in | |
TumbleListRow(tumble: item) | |
} | |
} | |
} | |
} | |
#Preview { | |
TumblingList(tumbling: [Tumbling(image: "highDrying", description: "mock data", summary: "more dummy data")]) | |
} | |
struct MainView: View { | |
@State var clean = [Laundry]() | |
var dataService = FetchData() | |
var body: some View { | |
NavigationStack { | |
VStack(spacing: 30) { | |
Text("Take care of your wash") | |
.font(.title2) | |
.padding(.top, 40) | |
Spacer() | |
NavigationLink { | |
LaundryList(laundry: $clean) | |
} label: { | |
LaundryView() | |
} | |
NavigationLink { | |
TumblingList(tumbling: clean) -> not working | |
} label: { | |
TumbleView() | |
} | |
Spacer() | |
}.onAppear(perform: { | |
clean = dataService.getLocalData() | |
}) | |
} | |
} | |
} | |
#Preview { | |
MainView() | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment