I have two screens: the first one displays a table with data, and the second we add this data.
When there is a lot of data, the application starts to slow down.
I have this code in viewDidLoad ():
let appDel: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate let context: NSManagedObjectContext = appDel.managedObjectContext do { let request = NSFetchRequest(entityName: "Diary") let result = try context.executeFetchRequest(request) if result.count > 0{ for item in result as! [NSManagedObject]{ let date = item.valueForKey("date") as! String if(self.dateArr.indexOf(date)==nil){ self.dateArr.append(date) } self.diary.append(item) } } else { self.dateArr = [] } }catch{ //print("ERROR READ DATA!") } In it, I check all the data in our table, check the dates in it (that would be divided into sections in the future) and add them all to the array, so that I can quickly work with them. I saw about this code on YouTube (there was no date check there), can it not be done like this and therefore the application slows down? And if so, could you tell me how to do it right, or can tell some article where it all signs.
request.propertiesToFetch = ["date"]beforeexecuteFetchRequestThis should reduce the number of calls to the database ... - Che