I am able to separate my persons objects into arrays of 2 randomly but I can't figure out how to display the pairs on my tableview. Here is my randomizer function.
func randomizer(array: [Person]) {
guard let array = fetchedResultsController.fetchedObjects else { return }
let randomGenerator = GKRandomSource.sharedRandom().arrayByShufflingObjects(in: array)
let splitSize = 2
let _ = stride(from: 0, to: randomGenerator.count, by: splitSize).map {
randomGenerator[$0..<min($0 + splitSize, randomGenerator.count)]
}
}
Here is my tableview functions:
func numberOfSections(in tableView: UITableView) -> Int {
guard let sections = PersonController.sharedController.fetchedResultsController.sections else { return 0 }
return sections.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
guard let sections = PersonController.sharedController.fetchedResultsController.sections else {
return 2 }
let sectionInfo = sections[section]
return sectionInfo.numberOfObjects
}