skip to Main Content

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


  1. 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
     }
    

    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 for nil, your test is .isEmpty.

    Login or Signup to reply.
  2. Youre personImages is an Optional UIImage Array, you so should add some Image or nil。UIImage? is a type

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search