Cannot convert value of type 'Meme!' to expected argument type '@noescape (Meme) throws -> Bool'

前端 未结 2 1600
梦毁少年i
梦毁少年i 2020-11-27 22:26

Here is the code:

    @IBAction func deleteMeme(sender: UIBarButtonItem) {
       if let foundIndex = MemeRepository.sharedInstance.memes.indexOf(selectedMem         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 22:35

    If you want to put the comparison inside the indexOf method itself, do it like this:

    if let foundIndex = MemeRepository.sharedInstance.memes.indexOf({
      UIImagePNGRepresentation($0.memedImage) == UIImagePNGRepresentation(selectedMeme.memedImage)})
    

    Probably not the best way to compare images. If you know the images are the same object, you can use:

    .indexOf({$0.memedImage == selectedMeme.memedImage})
    

    but if you want to compare them pixel by pixel or compare the same image scaled to different sizes, that is a little more complicated.

提交回复
热议问题