I have the following swift 3 code in an xcode 8 project:
if pictureImg.image == nil {
print("image nil")
}
if pictureImg.image != nil {
print("image not nil")
}
if pictureImg.image != nil {
imageData = UIImageJPEGRepresentation(pictureImg.image!, 0.5)!
}
At runtime, I end up with a peculiar result in the console:
image not nil
fatal error: unexpectedly found nil while unwrapping an Optional value
And so it appears that my pictureImg.image is in fact nil despite my previous identical if statement saying otherwise. Checks to see whether UIImageJPEGRepresentation is nil also results in the same error:
if UIImageJPEGRepresentation(pictureImg.img!, 0.5) == nil { *code* }
confirming the problem is definitely to do with pictureImg.image, or so it seems.
Is there an immediate/obvious issue with this code or will more information about the project need to be stated?