title: Access image from array swift
body: <p>I have created an image gallery in swift and I want to create a label under it that displays the image title.In my code, I have created An array that stores all the images and I want. And I want to create an <code>if</code> statement that when a certain image is displayed I want the text of the label to change.I am not sure how to access the certain image that is being displayed in the scroll view.</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>import UIKit
  
  class ViewController: UIViewController {
  @IBOutlet weak var mainscrollview: UIScrollView!
  var imageArray = [UIImage]()
  
      @IBOutlet var label: UILabel!
      override func viewDidLoad() {
          super.viewDidLoad()
          mainscrollview.frame = view.frame
          imageArray = [#imageLiteral(resourceName: "goku"), #imageLiteral(resourceName: "boruto"), #imageLiteral(resourceName: "tail"), #imageLiteral(resourceName: "sage"),#imageLiteral(resourceName: "tobi")]
  
          for i in 0..&lt;imageArray.count{
          let imageView = UIImageView()
              imageView.image = imageArray[i]
              imageView.contentMode = .scaleAspectFit
              let xPosition = self.view.frame.width * CGFloat(i)
              imageView.frame = CGRect(x: xPosition, y: 0, width: self.mainscrollview.frame.width,height: self.mainscrollview.frame.height)
              mainscrollview.contentSize.width = mainscrollview.frame.width * CGFloat(i + 1)
              mainscrollview.addSubview(imageView)
  
  
  
          }
  
  
      }
  </code></pre>
  
  <p><strong><em>However the line</em></strong> </p>
  
  <pre><code>if imageView.image = UIImageView.init(image: "goku")  {
  
  
              }
  </code></pre>
  
  <p>Gives Me a bunch of Errors</p>
  
  <h2>Pseudo Code</h2>
  
  <pre><code>if image == "goku" &amp;&amp; image_is_displayed_on_screen == true {
  label.text = "GOKU";
  }
  </code></pre>