Post not yet marked as solved
Figured this out as an issue with my struct data.
Post not yet marked as solved
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
Post not yet marked as solved
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)
Post not yet marked as solved
Thanks, this sort of helps. I sort of knew the difference between the two, but struggling to know the proper index in coredata.
Post not yet marked as solved
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.
Post not yet marked as solved
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
}
}
Post not yet marked as solved
Sorry last question ;). Am I accessing the data as
List(yelpbusinessdata?.reviews ?? []) { review in
...
Text(yelpbusinessdata?.reviews[review].user.name)`
}
Post not yet marked as solved
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")
}
}
Post not yet marked as solved
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 { }?
Post not yet marked as solved
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
Post not yet marked as solved
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
There's a firebase bug causing this. It's documented here https://github.com/firebase/firebase-ios-sdk/issues/6574
Thanks OOPer for the feedback. I've gone ahead and changed isFavorite to favoriteRunClubItem
Here's the definition
public class FavoriteItem:NSManagedObject, Identifiable {
@NSManaged public var isFavorite:Bool
@NSManaged public var misc:String?
@NSManaged public var name:String?
@NSManaged public var location:String?
@NSManaged public var date:String?
@NSManaged public var category:String?
@NSManaged public var dayofweek:Int
@NSManaged public var link:String?
@NSManaged public var hour:Int
@NSManaged public var minute:Int
}
extension FavoriteItem {
static func getAllFavorites() -> NSFetchRequest<FavoriteItem>{
let request:NSFetchRequest<FavoriteItem> = FavoriteItem.fetchRequest() as! NSFetchRequest<FavoriteItem>
let sortDescriptor = NSSortDescriptor(key: "category", ascending: true)
request.sortDescriptors = [sortDescriptor]
return request
}
}