In my UIViewController I call a method in another class which returns me a list of NSManagedObjects, which I instantiate in an array. Here is the code:
fileprivate var albumList = [Album]()
private func loadAlbums() {
APIHandler().getUsersAlbums() {
albums in
self.albumList = albums
self.collectionView?.reloadData()
}
}
But this was causing my array to have nil properties once loadAlbums was finished and APIHandler's instance cleared. I solved this for now by having an instance of APIHandler on my UIViewController and calling the function from there, like this:
let api = SpotifyAPIHandler()
fileprivate var albumList = [Album]()
private func loadAlbums() {
api.getUsersAlbums() {
albums in
self.albumList = albums
self.collectionView?.reloadData()
}
}
Still I am not happy with this. Why does this happen? How can I instantiate a completely new list?