Home > Software engineering >  Can't add a UIImage? to an array
Can't add a UIImage? to an array

Time:02-16

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?]
}

CodePudding user response:

Youre personImages is an Optional UIImage Array, you so should add some Image or nil。UIImage? is a type

CodePudding user response:

You are trying to add an array of UIImage? to the array, not a UIImage?.

.onTapGesture {
               isShowingPhotoPickerForPersonImage.toggle()
               Person.personImages.append(UIImage?) // Remove the brackets
 }
  • Related