I was following the webservices chapter exactly as it mentioned but my PhotoStore is returned as nil.
Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
This is my viewdidload() in PhotosViewController
`class PhotosViewController: UIViewController {
@IBOutlet var imageView: UIImageView!
var photoStore: PhotoStore!
override func viewDidLoad() {
super.viewDidLoad()
photoStore.fetchInterestingPhotos()
}
}`
Here is the PhotoStore.swift file
class PhotoStore {
private let session: URLSession = {
let config = URLSessionConfiguration.default
return URLSession(configuration: config)
}()
func fetchInterestingPhotos() {
let url = FlickrAPI.interestingPhotosUrl
let request = URLRequest(url: url)
let task = session.dataTask(with: request) {
(data, response, error) -> Void in
if let jsonData = data {
if let jsonString = String(data: jsonData,
encoding: .utf8) {
print(jsonString)
}
} else if let requestError = error {
print("Error fetching interesting photos: \(requestError)")
} else {
print("Unexpected error with the request")
}
}
task.resume()
}
}