title: Load data from JSON file to a table
body: <p>I have a Core Data model called 'List' with 4 attributes and wanted to populate the data from the JSON file to an array of type 'List'</p>
  
  <p>when I run the app, it gives me the error 'fatal error: Array index out of range'</p>
  
  <pre><code>var loadNames = [List]()
  
  var context = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext!
  var frc: NSFetchedResultsController = NSFetchedResultsController()
  func getFetchedResultsController() -&gt; NSFetchedResultsController {
      frc = NSFetchedResultsController(
          fetchRequest: listFetchRequest(),
          managedObjectContext: context,
          sectionNameKeyPath: "done",
          cacheName: nil)
      return frc
  }
  func listFetchRequest() -&gt; NSFetchRequest {
      let fetchRequest = NSFetchRequest(entityName: "List")
      let doneSortDescriptor = NSSortDescriptor(key: "done", ascending: false)
      let nameSortDescriptor = NSSortDescriptor(key: "firstName", ascending: true)
      fetchRequest.sortDescriptors = [doneSortDescriptor, nameSortDescriptor]
      return fetchRequest
  }
  func isFrequent(item: List) -&gt; Bool {
      return item.frequent == true
  }
  
  override func viewWillAppear(animated: Bool) {
      var readError:NSError?
      let filePath = NSBundle.mainBundle().pathForResource("NameList", ofType:"json")
      let data = NSData(contentsOfFile:filePath!, options: NSDataReadingOptions.DataReadingUncached, error:&amp;readError)
      var jData = NSJSONSerialization.JSONObjectWithData(data!, options: .MutableContainers, error: &amp;readError) as! NSArray
  
      for i in 0..&lt;jData.count {
          if let jfName = jData[i]["firstName"] as? String {
              if let jlName = jData[i]["lastName"] as? String {
                  if let jDone = jData[i]["done"] as? NSNumber {
                      if let jFrequent = jData[i]["frequent"] as? NSNumber {
  
                          loadNames[i].firstName = jfName //This is where the error is pointing.
                          loadNames[i].lastName = jlName
                          loadNames[i].done = jDone
                          loadNames[i].frequent = jFrequent
  
                          println(loadNames.count)
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>the variables all seem to be getting the data from the JSON file and the value of 'i' in the 'for' loop when the error is happening is '0'.</p>
  
  <p>I don't know why this is happening.</p>
  
  <p>the array count is returning 6, which is the actual amount of objects in the JSON file.</p>