How does CollectionView and collectionViewCell created with XIBs work with respect to getting data from array which is loaded from a url?

I created a collection view in a viewCOntroller XIB and a cell in a collectionviewCell Xib. it wirks with the static data sometiomes. Im also using Decoder to recieve a JSON data which i then pring out . Im trying to pass this data to the collection view but in numberOfItemsInSection return self.verses.count returns 0. Any ideas on how to fix this. thanks for the help.

You will need to follow the steps in which the data (the verses) is decoded from theJSON data and places in the the "verses" array for your data source to use.


You know that this "verses" array is empty (because verses.count == 0), so what happened to the data? Did decoding fail? Did the data get put into some other array instead?


Remember that in Swift, arrays are "value types". That means each named array variable that's supposed to hold verses contains a copy of the data. That means it's easy to move the data into the wrong variable, effectively causing the data to "disappear".

Hi,


Static data is different than data received and parsed from JSON. If you want to start with static data, then fetch new data via an API, you'll likely need a callback of some sort and perhaps a flag to tell your UICollectionView which data set to use (or 2 data sources, one static and one fetched).


Always remember to refresh your UICollectionVIew on the main thread and fetch any data on a background thread when applicable.

How does CollectionView and collectionViewCell created with XIBs work with respect to getting data from array which is loaded from a url?
 
 
Q