我正在使用Eureka iOS框架来创建一个表单。其中一行是图像行,允许用户附加图像。我有以下对象:
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]?
}
然后我设置我的对象:
var newReport = Report()
然后我从表单中获取值的字典,并尝试将对象中的图像保存到图像数组中:
if key.hasPrefix("Image") {
newReport.images?.append((value)! as! UIImage)
}
当我打印出newReport对象时,图像数组为空。如果我将上面的内容更改为:
if key.hasPrefix("Image") {
print (value as! UIImage)
}
然后,它输出以下内容:
<UIImage: 0x1c42ab220> size {1536, 1152} orientation 0 scale 1.000000
所以我知道其中有一个图像,但由于某种原因,它没有保存到图像数组中。
发布于 2018-06-08 06:37:28
您正试图将UIImages追加到尚未初始化的可选数组中。在使用它之前,请按如下方式进行初始化:
newReport.images = [UIImage]()
https://stackoverflow.com/questions/50745190
复制相似问题