The documentation for FirebaseUI-Firestore iOS is not very thorough, I've implemented the code but my collection view does not get populated:
class HomeViewController:UIViewController {
@IBOutlet weak var collectionView: UICollectionView!
var firestore:Firestore = Firestore.firestore()
override func viewDidLoad() {
super.viewDidLoad()
let query = firestore.collection("/offers")
let dataSource = collectionView.bind(toFirestoreQuery: query) { (collectionView, indexPath, documentSnapshot) -> UICollectionViewCell in
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! OfferHolderCollection
print("POPULATING")
cell.myLabel?.text = documentSnapshot.data()?["name"] as? String
return cell
}
}
On Android, the adapter.startListening() method would be placed inside onResume() in order to start retrieving data, but there seems to be no such method for iOS. Should the code above be enough to start retrieving data?
Found my error. From the FirebaseUI source code comments:
* The returned data source is not retained by the collection view and must be
* retained or it will be deallocated while still in use by the collection view.
And indeed, the documentation example does store it in self.datasource, whereas my code stored it locally. The issue was thus fixed by making datasource a member of the ViewController.