When selecting the photos to display in the user’s profile, while doing a .onTapGesture
to append a UIImage into an array of them, Xcode throws No exact matches in call to instance method 'append'
.onTapGesture {
isShowingPhotoPickerForPersonImage.toggle()
Person.personImages.append([UIImage?])
}
struct Person: Hashable, Identifiable {
var personImages: [UIImage?]
}
2
Answers
You are trying to add an array of
UIImage?
to the array, not aUIImage?
.As noted in the comments, this is pretty non-sensical. You need to actually have an image to append. Lastly, the nice thing about using an
Array
is that you do not need to use an optional value in its declaration. It can always be simply empty if you don’t have a value to declare it with originally. Then, instead of testing fornil
, your test is.isEmpty
.Youre
personImages
is an Optional UIImage Array, you so should addsome Image
or nil。UIImage?
is a type