我正在使用SDWebImage从url获取图像,并将其分配给这样的数组.
let imgUrl = arrProduct?[indexPath.section].images[indexPath.row].url
let placeholderImage = UIImage(named: "appLogo.jpg")
cell.prdImgView.sd_setImage(with:imgUrl,
placeholderImage:placeholderImage,
options: []) { (image, error, imageCacheType, imageUrl) in
arrayOfSelectedImages.append(image!)
}现在我只是不想添加到这样的数组中。相反,在将图像添加到arrayOfSelectedImages之后,我希望在didSet中更新这个数组值,并清空arrayOfSelectedImages数组,这样每当数组获得一个新值时,它都会更新didSet和&arrayOfSelectedImage中的值。最后,我的数组在didSet中将得到我需要的所有图像,我可以将这些图像传递给其他一些view...How,我能实现这一点吗?
发布于 2017-11-03 10:50:52
不完全确定这是否是您想要的,但是如果您修改数组,而不仅仅是分配数组,didSet就会触发一个作为数组的属性。下面是一个示例:
struct A
{
var anArray = [1, 2, 3]
{
didSet
{
print("Hi, there!")
anArray.remove(at: 0)
}
}
}
var a = A()
a.anArray.append(4)
// Prints Hi there!
print(a.anArray)
// prints [2, 3, 4]https://stackoverflow.com/questions/47093280
复制相似问题