Swift 3 Xcode 8 Collection View Reload Data with Segmented Control

https://stackoverflow.com/questions/44580287/swift-3-xcode-8-collection-view-reload-data-with-segmented-control

I'm displaying 2 sets of data from 2 different arrays based on the segmented control selected index. Everything works fine, all the correct data loads up. However, one thing very strange happens:
When I press the other segmented control 'button', the collection view is supposed to switch pretty smoothly (implemented reloadData() in the segmented control IBAction). But it flashes very quickly before the 'correct data' is loaded up. I've tried restarting Xcode and even gave it to a friend to test however, the quick 'flash' remains. It also happens when I go back to segmented control 'button1' from segmented control 'button 2'.
When I look closely at what flashes, it turns out that the collection view displays data from my array in a random order (or so it appears to be) before quickly (very quickly!) switching back to its 'correct' order.
Here is my view controller:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

var array1 = ["Red", "Yellow", "Purple"]
var array2 = ["Apple", "Banana", "Grape"]

@IBAction func segmentedControl(_ sender: UISegmentedControl) {
collectionView.reloadData()
// Reload Data
collectionView.reloadItems(at: collectionView.indexPathsForVisibleItems)
// Prevents 'flash' from .reloadData()
}

@IBOutlet weak var segmentedOutlet: UISegmentedControl!
// Creates an outlet for segmented control (that can be set)
@IBOutlet weak var collectionView: UICollectionView!

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
switch segmentedOutlet.selectedSegmentIndex {
case 0 : return array1.count
case 1 : return array2.count
default: return 0
}
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! collectionViewCell

switch segmentedOutlet.selectedSegmentIndex {
case 0 : cell.button.setTitle(array1[indexPath.row], for: .normal)
case 1 : cell.button.setTitle(array2[indexPath.row], for: .normal)
default : break
}
return cell
}

Ok so I have found a way to get around this. Basically after:
collectionView.reloadData()
add
collectionView.reloadItems(at: collectionView.indexPathsForVisibleItems)
to get around the obnoxious and rather annoying 'flashes' you might get when switching segmented controls with collection views.