I have what may be a dumb question but I've been pulling my hair out trying to understand this. I am still learning Swift and SwiftUI and some of it hasn't quite clicked yet so I apologize if this seems naive.
I have built navigation into my app based on the Landmark app and other examples. I have a tricky JSON structure that I am trying to understand how to use to navigate.
I want to use the item in .self to filter to the category value that it matches and have the navigation link update accordingly. I just cannot figure out how to do this due to the structure.
This works works great for me to see the items in the array associated with the given day:
Text("Tuesday")
.font(Font.custom("StencilWWII", size:60))
ForEach(plan.tuesday, id: \.self) { item in
Text(item)
The JSON is currently structured like this:
[
{
"program" : "6 Month",
"id": "Block 1",
"weeks": "1 To 4",
"description": "In the first block of this program, you’ll build a baseline of general fitness and test yourself to evaluate your strengths and weaknesses.",
"monday": ["Warmup", "Max Test","Finisher", "Cooldown"],
"tuesday": ["Warmup", "Challenge", "Finisher", "Cooldown"],
"wednesday" : ["Warmup", "Max Test" , "Challenge", "Finisher", "Cooldown"],
"thursday" : ["Warmup", "Challenge", "Finisher", "Cooldown"],
"friday" : ["Warmup", "Challenge", "Finisher", "Cooldown"],
"saturday" : ["Rest", "Recovery"],
"sunday" : ["Rest", "Recovery"]
}
]
With my struct for the JSON setup like this:
import SwiftUI
import CoreLocation
struct Plan : Hashable, Codable, Identifiable {
var id: String
var program, weeks, description: String
var monday, tuesday, wednesday, thursday, friday, saturday, sunday : [String]
}
I am attempting something like this but it's not working and just sends me to the first index in my category data (at least that's happening!) But it's not filtering and I don't have any text outputting . Additionaly I don't think I am setting up the for each correctly:
ForEach(userData.plans.filter {$0.monday.contains(category.id)}) { day in
NavigationLink(
destination: WorkoutList(workout: workout,category: category, plan: plan)) {
//Text(day)
}
I can get the .\self text to show out of the ForEach but it's not filtering to the category view that I am wanting.
As a note, the monday - sunday arrays include values that are found in the id of my Category data as seen below:
{
"id": "Warmup",
"category" : "warmup",
"name": "Warmups",
UPDATE When I enter the below code:
ForEach(plan.monday, id: \.self) { item in
NavigationLink(destination: CategoryList(category: category, workout: workout, plan: plan))
Text(item)
I get this error
Missing argument for parameter #1 in call, Insert '<#LocalizedStringKey#>, '
I really appreciate any insight/advice you have on this. I have tried everything I can think of and am jut a bit stuck. Thank you!