Reputation: 330
rowDescriptor
is a AnyObject?
type, I get convert self.rowDescriptor?.value
to images
. I want to add image to the self.rowDescriptor?.value
. I failed to do it as below. images
has one value. but self.rowDescriptor?.value
still empty. I can't find any document about it. what's the reason about it.
var images :[UIImage] = self.rowDescriptor?.value as! [UIImage]
if let image = editedImage {
images.append(image)
} else {
images.append(originalImage!)
}
Upvotes: 0
Views: 119
Reputation: 17576
The array type in Swift is a struct. Structs in swift are value types not reference types. To clarify:
images
contains a copy of self.rowDescriptor?.value
images.append(
changes the copy images
, not the original value in your rowDescriptor.value
You want to change self.rowDescriptor?.value
so just set that to your newly changed image
s array.
self.rowDescriptor?.value = images
To fix, add self.rowDescriptor?.value = images
.
Upvotes: 3