title: Swift 2: How can I assign a dynamic number of strings to an array of Strings?
body: <p><strong>Context:</strong> </p>
  
  <p>I'm attempting to create an app that populates a UICollectionView (tvOS) based on the contents of a folder in a local server I'm running. The way I'm trying to do this (and it may be completely wrong way) is to 'scrape' the html of my server pages.</p>
  
  <p>I have the following property defined: </p>
  
  <p><code>let moviesArray: [String] = ["&lt;li&gt;Example 1&lt;/li&gt;", "&lt;li&gt;Example 2&lt;/li&gt;"]</code></p>
  
  <p>My UICollectionView will return the number of UICollectionViewCell's equal to <code>moviesArray.count</code> so I need this number (along with additional data that I won't speak to in this question).</p>
  
  <p><strong>Problem:</strong></p>
  
  <p>The number of files/folders I add to my server is dynamic and will increase / decrease depending on what movies I add to it or delete from it. This will obviously change the html which is returned.</p>
  
  <p>I have the following piece of code that returns the html of my local server's URL and converts it to a string. I then create a substring of that based on a range, and then split out each individual <code>&lt;li&gt;</code> element from the html. Here's the code:</p>
  
  <pre><code>     do {
  
          let url:NSURL? = NSURL(string: "http://localhost:8888/Files/movies/")
  
          // 'contentsOfURL' returns the html code of the page
          let html:String? = try NSString(contentsOfURL: url!, encoding: NSUTF8StringEncoding) as String
          print(html)
  
          // creates a substring of 'html' based on a range defined below
          let ulString = html![(html?.startIndex.advancedBy(164))!...(html?.endIndex.advancedBy(-22))!]
          print("&lt;ul&gt; substring is: \(ulString)")
  
          // Splits each &lt;li&gt; into a separate string
          let liSplit = ulString.characters.split{$0 == "\n"}.map(String.init)
          print("li 1 is: \(liSplit[0])")
          print("li 2 is: \(liSplit[1])")
          print("li 3 is: \(liSplit[2])")
  
      } catch {
          print("the error is: \(error)")
      }
  </code></pre>
  
  <p><strong>My Question:</strong></p>
  
  <p>How can I add or remove <code>String</code> objects to <code>self.moviesArray</code> based on the number of <code>&lt;li&gt;</code> elements that are in the html string which is returned? How will I assign each member of <code>liSplit</code> to <code>self.moviesArray</code> if it is a dynamic number?</p>