I want the getPhotos class method to be executed to the end, and only then the code after. Otherwise, the photos are not displayed in the collection. How can this be achieved?
// MARK: - Text Field Delegate
extension CollectionViewController: UITextFieldDelegate {
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
collectionManager.getPhotos(searchTerm: textField.text!)
print("finish")
self.collectionView?.reloadData()
return true
}
}
Implementation of the getPhotos method:
func getPhotos(searchTerm: String) -> [FlickrPhoto] {
loader.searchFlickr(for: searchTerm) { searchResults in
switch searchResults {
case .error(let error):
print("Error Searching: \(error)")
case .results(let results):
self.searchPhotos = results.searchResults
}
}
return searchPhotos
}