Unexpectedly found nil while unwrapping optional value
Try doing it this way:
if let imageData = pictures[string] {
if let image = UIImage(data: imageData) {
imageView.image = image
}
}
Assuming that string
is a valid key.
You are dealing with optionals, so conditionally unwrap each return object before using it.
Forced unwrapping is dangerous and should only be used when you are absolutely sure that an optional contains a value. Your imageData may not be in the correct format to create an image, but you are forcibly unwrapping it anyway. This is okay to do in Objective-C as it just means nil
objects get passed around. Swift is not so tolerant.