0

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

}
Nicholas
  • 5
  • 5
  • Have you looked at the `UITableView` delegate and data source protocols? That's how you get data into tables. – Tom Harrington Jan 25 '17 at 17:50
  • I just edited it to show that, but I am confused on how to display just two rows in each section. I want to have a section for each pair, then display those two person objects inside the sections – Nicholas Jan 25 '17 at 18:00

1 Answers1

1

How are you keeping track of your pairs in your data model? If you store your pairs in your data model you should be able to use your FRC sectionKey on that property to get the correct number of sections back.