Post

Replies

Boosts

Views

Activity

Reply to Fetch Core Data Issue
Okay I see your point this will save each of my instances that I have. The issue is my fetchSave() func then. I should be able to see my favourites when I restart the app.  override func viewDidLoad() {     super.viewDidLoad()     fetchSave() //don't seem to have any saveFavs in my array when it restarts     if prefArr.count == 0 {     print("There are 0 favourites")     self.tableView.separatorStyle = UITableViewCell.SeparatorStyle.none     } else {     print("There are favourites")     DispatchQueue.main.asyncAfter(deadline: .now() + 300) {         self.reviewRating.requestReview(isWrittenReview: false)       }     }   }  func fetchSave() { //If I have any number of favourites and restart the app this code block executes     if prefArr.count == 0 {       print("No saved favourites")     } else {     let fetchRequest: NSFetchRequest<CurrentPlayers>     fetchRequest = CurrentPlayers.fetchRequest()     do {       let objects = try context.fetch(fetchRequest)       print("These are how many saved favourites I have: \(objects.count)")       tableView.reloadData()     } catch {       print("Fetch failed")     }    } }
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to Fetch Core Data Issue
Please tell exactly where you stand now: are the favorites saved corectly  When I click save it prints out all the favourites I saved as a CoreData entity so i think it's saved. What are all print output you get when you restart the app ? When I restart the app it prints no saved favourites and there are 0 favourites. provide more precise output with         print("There are favourites", prefArr.count) This prints how many favourites I have, depending on the number I added.
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to Fetch Core Data Issue
Okay so I got rid of fetchSave I don't think I need it since when it saves it should not need to be fetched because I add it to the array. I still have trouble getting the save to work.    @IBAction func save(_ sender: UIBarButtonItem) {     // Assign values to the entity's properties     for o in prefArr {     let saveFav = CurrentPlayers(context: context)     saveFav.yahooName = o.yahooName     saveFav.team = o.team     saveFav.position = o.position     saveFav.photoUrl = o.photoUrl     // To save the new entity to the persistent store, call     // save on the context     print("These are my saved objects: \(saveFav)")     do {       try context.save()       prefArr.append(saveFav) //favourite is added     } catch {       print("error is: \(error)")     }   }   } }
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’21
Reply to Fetch Core Data Issue
What problem exactly ? No save at all ? partial save ? No save it all. Could you show more of convenience init ? It seems you get only one value. I added a prefArr.count to it. If I add a player to my favourites I get this. It is a Core Data entity as you can see and I also get how many favourites I have from the count. These are my saved objects: <CurrentPlayers: 0x6000033fd630> (entity: CurrentPlayers; id: 0x600001031f80 <x-coredata:///CurrentPlayers/tB4FE931D-0582-445E-BFAB-099B58D904391054>; data: {   firstName = nil;   jerseyNumber = 0;   lastName = nil;   photoUrl = "https://s3-us-west-2.amazonaws.com/static.fantasydata.com/headshots/nhl/low-res/30000007.png";   position = G;   status = nil;   team = MON;   yahooName = "Carey Price"; }) 1
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’21
Reply to Fetch Core Data Issue
Another update I modified my save function and I think it is consistent with my print results. Like it prints 3 favourites when there are 3 favourites and shows me my saved favourites. I just need need to figure out how to retrieve the data when the app restarts because nothing is saved. Any input would really help.    @IBAction func save(_ sender: UIBarButtonItem) {     let entity = NSEntityDescription.entity(forEntityName: "CurrentPlayers", in: context)!     let saveFav = CurrentPlayers(entity: entity, insertInto: context)     for o in prefArr {       saveFav.yahooName = o.yahooName       saveFav.team = o.team       saveFav.position = o.position       saveFav.photoUrl = o.photoUrl     do {       try context.save()       print("These are my saved objects: \(saveFav)")       print("how many saved objects: \(prefArr.count)")     } catch {       print("error is: \(error)")     }     }   } }
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’21
Reply to Fetch Core Data Issue
Okay I see your point this will save each of my instances that I have. The issue is my fetchSave() func then. I should be able to see my favourites when I restart the app.  override func viewDidLoad() {     super.viewDidLoad()     fetchSave() //don't seem to have any saveFavs in my array when it restarts     if prefArr.count == 0 {     print("There are 0 favourites")     self.tableView.separatorStyle = UITableViewCell.SeparatorStyle.none     } else {     print("There are favourites")     DispatchQueue.main.asyncAfter(deadline: .now() + 300) {         self.reviewRating.requestReview(isWrittenReview: false)       }     }   }  func fetchSave() { //If I have any number of favourites and restart the app this code block executes     if prefArr.count == 0 {       print("No saved favourites")     } else {     let fetchRequest: NSFetchRequest<CurrentPlayers>     fetchRequest = CurrentPlayers.fetchRequest()     do {       let objects = try context.fetch(fetchRequest)       print("These are how many saved favourites I have: \(objects.count)")       tableView.reloadData()     } catch {       print("Fetch failed")     }    } }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Fetch Core Data Issue
Please tell exactly where you stand now: are the favorites saved corectly  When I click save it prints out all the favourites I saved as a CoreData entity so i think it's saved. What are all print output you get when you restart the app ? When I restart the app it prints no saved favourites and there are 0 favourites. provide more precise output with         print("There are favourites", prefArr.count) This prints how many favourites I have, depending on the number I added.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Fetch Core Data Issue
Okay so I got rid of fetchSave I don't think I need it since when it saves it should not need to be fetched because I add it to the array. I still have trouble getting the save to work.    @IBAction func save(_ sender: UIBarButtonItem) {     // Assign values to the entity's properties     for o in prefArr {     let saveFav = CurrentPlayers(context: context)     saveFav.yahooName = o.yahooName     saveFav.team = o.team     saveFav.position = o.position     saveFav.photoUrl = o.photoUrl     // To save the new entity to the persistent store, call     // save on the context     print("These are my saved objects: \(saveFav)")     do {       try context.save()       prefArr.append(saveFav) //favourite is added     } catch {       print("error is: \(error)")     }   }   } }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Fetch Core Data Issue
What problem exactly ? No save at all ? partial save ? No save it all. Could you show more of convenience init ? It seems you get only one value. I added a prefArr.count to it. If I add a player to my favourites I get this. It is a Core Data entity as you can see and I also get how many favourites I have from the count. These are my saved objects: <CurrentPlayers: 0x6000033fd630> (entity: CurrentPlayers; id: 0x600001031f80 <x-coredata:///CurrentPlayers/tB4FE931D-0582-445E-BFAB-099B58D904391054>; data: {   firstName = nil;   jerseyNumber = 0;   lastName = nil;   photoUrl = "https://s3-us-west-2.amazonaws.com/static.fantasydata.com/headshots/nhl/low-res/30000007.png";   position = G;   status = nil;   team = MON;   yahooName = "Carey Price"; }) 1
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Fetch Core Data Issue
Another update I modified my save function and I think it is consistent with my print results. Like it prints 3 favourites when there are 3 favourites and shows me my saved favourites. I just need need to figure out how to retrieve the data when the app restarts because nothing is saved. Any input would really help.    @IBAction func save(_ sender: UIBarButtonItem) {     let entity = NSEntityDescription.entity(forEntityName: "CurrentPlayers", in: context)!     let saveFav = CurrentPlayers(entity: entity, insertInto: context)     for o in prefArr {       saveFav.yahooName = o.yahooName       saveFav.team = o.team       saveFav.position = o.position       saveFav.photoUrl = o.photoUrl     do {       try context.save()       print("These are my saved objects: \(saveFav)")       print("how many saved objects: \(prefArr.count)")     } catch {       print("error is: \(error)")     }     }   } }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Fetch Core Data Issue
Alright I will close this thread because I got more updates.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’21