title: Core Data in Swift: Only saving last object in a for loop
body: <p>I'm trying to save multiple objects in Core Data to the IPodSongs entity in a <code>for</code> loop, namely the title of the song currently in the <code>for song in result{}</code> loop. But my code only saves the very last song in the loop, and just keeps overwriting the same object. Instead of overwriting the same object, I need to create a new object each time. What am I doing wrong?</p>
  
  <pre><code>func fetchiPodSongsOnSignup() {
  
          var appDel: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
  
          var context: NSManagedObjectContext = appDel.managedObjectContext!
  
          var newSong = NSEntityDescription.insertNewObjectForEntityForName("IPodSongs", inManagedObjectContext: context) as! NSManagedObject
  
          var request = NSFetchRequest(entityName: "IPodSongs")
  
          request.returnsObjectsAsFaults = false
  
          var results = context.executeFetchRequest(request, error: nil)
  
  
          let query = MPMediaQuery.songsQuery()
  
          let result = query.collections as! [MPMediaItemCollection]
  
          for song in result {
  
              for song in song.items as! [MPMediaItem] {
  
                  newSong.setValue("\(song.valueForProperty(MPMediaItemPropertyTitle))", forKey: "title")
  
                  println(newSong)
  
                  context.save(nil)
  
              }
          }    
  </code></pre>