title: Change the image of a selected NSAttributedString
body: <p>I have this code for creating an Attributed String with an image on a UITextView </p>
  
  <blockquote>
    <p>func setImageOnString(imageName: String) {</p>
  
  <pre><code>    let fullString = NSMutableAttributedString(attributedString: attributedText)
      let imageAttachment = NSTextAttachment()
  
      imageAttachment.image = #imageLiteral(resourceName: "UncheckedImage")
      imageAttachment.bounds = CGRect(x: 0, y: 0, width: 14, height: 14)
  
      let image1String = NSAttributedString(attachment: imageAttachment)
      let myCustomAttribute = [ "MyCustomAttributeName": "some value"]
  
      fullString.append(image1String)
      fullString.addAttributes(myCustomAttribute, range: selectedRange)
      self.attributedText = fullString
  
  }
  </code></pre>
  </blockquote>
  
  <p>But then I can't find a way of changing this image when something happen like a touch. The problem isn't the touch, it is changing the image.</p>