title: Initializing variables in Swift without var/let
body: <p>I'm new to Swift so this might come as a noob question but I will be thankful if someone cleared the doubt because I cannot find any explanation online. While using for-in loop, sometimes the variables have not been initialized before and still there is no compiler error. Sometimes if I try to write var/let before them, it shows error- <strong>'let' pattern cannot appear nested in an already immutable context</strong></p>
  
  <p>e.g., in the code below, why have the variables movie and releasedDate not been initialized before?</p>
  
  <pre><code>class MovieArchive {
  func filterByYear(year:Int, movies:Dictionary&lt;String, Int&gt; ) -&gt; [String]{
      var filteredArray = [String]()
      for (movie, releaseDate) in movies {
          if year == releaseDate {
              filteredArray.append(movie)
          }
      }
      return filteredArray
  }
  
  }
  
  var aiThemedMovies = ["Metropolis": 1927, "2001: A Space Odyssey": 1968, "Blade Runner": 1982, "War Games": 1983, "Terminator": 1984, "The Matrix": 1999, "A.I.": 2001, "Her": 2013, "Ex Machina": 2015]
  
  var myArchive = MovieArchive()
  myArchive.filterByYear(year: 2013
  , movies: aiThemedMovies)
  </code></pre>
  
  <p>Thanks in advance for any help :)</p>