title: swift - JSON to NSManagedObject
body: <p>I have a JSON data which I want to map to CoreData when my tableview loaded at first launch.
  I found a way to do it in cellForRowAtIndexPath, but this way I can only save the data to CoreData when the cell is displayed.
  I want to do it once for all cells.</p>
  
  <pre><code>    var yazarMakaleListesi: [JSON]? = []
      var authorList = [AuthorList]() // My CoreData
  
      override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
  
          var cell = tableView.dequeueReusableCellWithIdentifier("YazarCell") as! YazarTableViewCell     
          cell.yazar = self.yazarMakaleListesi?[indexPath.row]
  
          cell.yazar = self.yazarMakaleListesi?[indexPath.row]
          let authorName = self.yazarMakaleListesi?[indexPath.row]["author_name"].string
          let authorID = self.yazarMakaleListesi?[indexPath.row]["author_id"].int
          let authorImage = self.yazarMakaleListesi?[indexPath.row]["author_image"].string
          let newspaperID = self.yazarMakaleListesi?[indexPath.row]["newspaper_id"].string
          let newspaperName = self.yazarMakaleListesi?[indexPath.row]["newspaper"].string
          let newsPaperImage = self.yazarMakaleListesi?[indexPath.row]["author_image"].string
  
          let articleEntity = NSEntityDescription.entityForName("AuthorList", inManagedObjectContext: self.context!)
          let newAuthor = AuthorList(entity: articleEntity!, insertIntoManagedObjectContext: self.context!)
  
          newAuthor.authorName = authorName!
          newAuthor.authorImage = authorImage!
          newAuthor.newspaperName = newspaperName!
          newAuthor.newsPaperImage = newsPaperImage!
          newAuthor.authorID = authorID!
  
          var saveError: NSError?
          self.context!.save(&amp;saveError)
  
          if let _error = saveError {
              println("\(_error.localizedDescription)")
          } else {
              println("Author Saved!")
          }
  
          var error: NSError?
          let request = NSFetchRequest(entityName: "AuthorList")
          let results = self.context!.executeFetchRequest(request, error: &amp;error) as! [AuthorList]
  
      return cell
      }
  </code></pre>
  
  <p>I get the JSON data here:</p>
  
  <pre><code>   func loadYazar(){ 
          if (gazeteid != nil){
              let url = "http:myapi.com" + String(gazeteid)
              Alamofire.request(.GET, url).responseJSON { (Request, response, json, error) -&gt; Void in
                  if (json != nil){
                      var jsonObj = JSON(json!)
                      if let data = jsonObj["authors"].arrayValue as [JSON]?{
                          self.yazarMakaleListesi = data
                          self.tableView.reloadData()
                      }
                  }
              }
          }
     }
  </code></pre>
  
  <p>EDIT : I get my jsonresponse here, implemented @ thefredelement's recommendation.
  But I get " 'JSON' does not have a member named 'valueForKey'" from line:</p>
  
  <p>newFakeCoreDataObject.authorName = jsonResult.valueForKey("authorName") as! String</p>
  
  <pre><code>Alamofire.request(.GET, url).responseJSON { (Request, response, json, error) -&gt; Void in
      if (json != nil){
          var jsonObj = JSON(json!)
          if let jsonResults = jsonObj["authors"].arrayValue as [JSON]?{
              self.yazarMakaleListesi = jsonResults
              var error : NSError?
              for jsonResult in jsonResults {
                  let newFakeCoreDataObject = FakeCoreDataObject()
                  newFakeCoreDataObject.authorName = jsonResult.valueForKey("authorName") as! String
                  self.context!.save(&amp;error)                          
              }                 
                  self.tableView.reloadData()
          }
      }   
  </code></pre>