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: