Figured this out as an issue with my struct data.
Post
Replies
Boosts
Views
Activity
Sort of figured it out. Has to do when using segmented style picker that throws of geo reader.
I figured it out.
Using the below worked
ForEach(planData.trainingdata.prefix(1)) { index in
ForEach(dateRange, id: \.self) { day in
I think I figured it out sort of, this though iterates through daterange and then planData
ForEach(planData.trainingdata) { index in
ForEach(dateRange, id: \.self) { day in
Correct. Ideally 09/08, 09/09 would match with the appropriate day. Here's a pretty bare bones of the code. Sorry I can't get it formatted right
@StateObject var planData = DownloadHansonData()
@AppStorage("startDate") var userStartDate: Date = Date()
@AppStorage("raceDate") var userRaceDate: Date = Date()
@State var startDate = Date()
@State var endDate = Date()
@State var dateRange: [Date] = []
var body: some View {
VStack {
// ForEach(dateRange, id: \.self) { day in
ScrollView {
ForEach(planData.trainingdata) { index in
HStack {
Text("\(index.day0.day) - \(index.day0.exercise)")
Spacer()
}
HStack {
Text("\(index.day1.day) - \(index.day1.exercise)")
Spacer()
}
HStack {
Text("\(index.day2.day) - \(index.day2.exercise)")
Spacer()
}
HStack {
Text("\(index.day3.day) - \(index.day3.exercise)")
Spacer()
}
HStack {
Text("\(index.day4.day) - \(index.day4.exercise)")
Spacer()
}
HStack {
Text("\(index.day5.day) - \(index.day5.exercise)")
Spacer()
}
HStack {
Text("\(index.day6.day) - \(index.day6.exercise)")
Spacer()
}
// }
}
.padding()
}
}
}
So here's where I'm getting hung up. I created a function in the view and then call removeFavorite, but the compiler fails.
@Environment(\.managedObjectContext) var managedObjectContext
@FetchRequest(fetchRequest: FavoriteItem.getAllFavorites()) var favorites:FetchedResults<FavoriteItem>
func removeFavorite(at offsets: IndexSet) {
for item in offsets {
let favorite = favorites[item]
managedObjectContext.delete(favorite)
}
}
Text("Foo")
.onTapGesture(perform: removeFavorite)
Thanks, this sort of helps. I sort of knew the difference between the two, but struggling to know the proper index in coredata.
i'm also curious is anyone was able to figure this out.
Thank you. I'll be sure to do better in my posts in the future.
Sorry! I had thought I revealed those. Here they are
// MARK: - Welcome
struct Welcome: Codable, Identifiable {
let id = UUID()
let reviews: [Review]
let total: Int
let possibleLanguages: [String]
enum CodingKeys: String, CodingKey {
case reviews, total
case possibleLanguages = "possible_languages"
}
}
// MARK: - Review
struct Review: Codable, Identifiable {
let id: String
let url: String
let text: String
let rating: Int
let timeCreated: String
let user: User
enum CodingKeys: String, CodingKey {
case id, url, text, rating
case timeCreated = "time_created"
case user
}
}
// MARK: - User
struct User: Codable {
let id: String
let profileURL: String
let imageURL: String
let name: String
enum CodingKeys: String, CodingKey {
case id
case profileURL = "profile_url"
case imageURL = "image_url"
case name
}
}
Sorry last question ;). Am I accessing the data as
List(yelpbusinessdata?.reviews ?? []) { review in
...
Text(yelpbusinessdata?.reviews[review].user.name)`
}
In JSON, dictionary-like structure is called object. Thank you! I'm learning here so this is helpful. I appreciate your patience as well.
I'm sort of struggling to grasp what you're saying. How is this different when a response is [ ] vs { }?
In my view I have Welcome declared as @State var yelpbusinessdata: [Welcome] = [] and I'm calling the data as
List(yelpbusinessdata) { review in
..
}
.onAppear{
print("on appear calling data")
Yelp().getBusinessInfo {
(yelpbusinessinfo) in
self.yelpbusinessdata = yelpbusinessinfo
print("we got yelp reviews")
}
}
That's fair. I'm still struggling to understand why I'm getting this error Cannot assign value of type 'Welcome?' to type '[Welcome]'. My guess is that is has to how the data is being returned because it's not an array 1[ ] and dictionary { }?
Thanks @OOPer! Does doing it the way you show differ with the error catching I have in place?
if let error = error {
print("Error took place \(error)")
return
}
Do I declare my state as @State var yelpbusinessinfo: [Welcome] = [] or because it's not an array
Thanks OOPer! Does doing it the way you show differ with the error catching I have in place?
if let error = error {
print("Error took place \(error)")
return
}
Do I declare my state as @State var yelpbusinessinfo: [Welcome] = [] or because it's not an array