title: Loading image showcase in array from url with forward, back buttons in swift
body: <p>The code below works perfectly to display images from an already pre-existing array "var files". I want to load a list of image urls from another url to put in that array. </p>
  
  <pre><code>class ViewController: UIViewController {
  
      @IBOutlet weak var fwdBtn: UIButton!
      @IBOutlet weak var bkBtn: UIButton!
      @IBOutlet weak var imageView: UIImageView!
  
      var files = ["https://www.testsite.com/1.jpg", "https://www.testsite.com/2.jpg”,”https://www.testsite.com/3.jpg"]
  
      var count = 0
  
      //Foward Button
      @IBAction func fwdBtn(_ sender: Any) {
          if (count &lt; (files.count - 1)) {
              count = count + 1
              imageView.image = UIImage(named: files[count])
          }
      }
  
      //Back Button
      @IBAction func bkBtn(_ sender: Any) {
          if (count &gt; 0) {
              count = count - 1
              imageView.image = UIImage(named: files[count])
          }
      }
  
      override func viewDidLoad() {
          imageView.image = UIImage(named: files[count])
  }
  </code></pre>
  
  <p>I have tried to do the following to load images from URL but it either gives me a '<strong>nil</strong>' error, or a '<strong>Cannot use instance member within property initializer; property initializers run before 'self' is available</strong>'</p>
  
  <pre><code>var files = [myurl()]
  
  func myurl() {
      let myURLString = "https://www.testsite.com/image_list.php"
      guard let myURL = URL(string: myURLString) else {
          print("Error: \(myURLString) doesn't seem to be a valid URL")
          return
      }
  
      do {
          let myHTMLString = try String(contentsOf: myURL)
  
          let imagesOutput = myHTMLString
  
  
      } catch let error {
          print("Error: \(error)")
      }
  }
  </code></pre>
  
  <p>The output image url list on image_list.php is just a plain text, comma separated url list without any html formatting like this:</p>
  
  <pre><code>https://www.testsite.com/1.jpg,https://www.testsite.com/2.jpg,https://www.testsite.com/3.jpg
  </code></pre>
  
  <p>I want to add the list of image urls from another url into an array in the declarations part of the ViewController. How do I properly integrate this into my code? I guess it doesn't have to be exactly that as long as it works. Thanks!</p>