I am using the Eureka iOS framework to create a form. One of the rows is an image row that allows users to attach an image. I have the below object:
struct Report {
var title: String?
var detail: String?
var immactions: String?
var recommactions: String?
var notifications: String?
var identified: String?
var date: String?
var time: String?
var origDept: String?
var origOwned: String?
var images: [UIImage]?
}
I then set my object:
var newReport = Report()
And then I take the dictionary of values from my form and try to save the image to the images array from the object:
if key.hasPrefix("Image") {
newReport.images?.append((value)! as! UIImage)
}
When I print out the newReport object, the images array is nil. If I change the above to this:
if key.hasPrefix("Image") {
print (value as! UIImage)
}
then it prints the following:
<UIImage: 0x1c42ab220> size {1536, 1152} orientation 0 scale 1.000000
So I know there is an image in there but for some reason it is not getting saved to the images array.
You are attempting to append UIImages to an optional array that hasn't been initialized. Before you use it, initialize it like so:
newReport.images = [UIImage]()