title: Saving a Dictionary to Core Data
body: <p>My app parses podcast RSS feeds. I use 2 entities: Podcasts (to hold podcast-related data) and Episodes (Episodes data like summaries etc). After parsing a feed, I store the list of episodes in an Array called "episodesToDisplay". When a user subscribes to a podcast, I want to save the data held by that array in Core Data. Here is my code which throws an error on the annotated line below:</p>
  
  <pre><code>class Podcasts: UITableViewController {
  var currentPodcast: Podcasts!
  
      override func viewDidLoad() {
      super.viewDidLoad()
  let podcastsEntity = NSEntityDescription.entityForName("Podcasts", inManagedObjectContext: self.managedContext)
      let podcastsFetch = NSFetchRequest(entityName: "Podcasts")
      var error: NSError?
  
      let result = self.managedContext.executeFetchRequest(podcastsFetch, error: &amp;error) as [Podcasts]?
      if let resu = result {
          println("res is \(resu.count)")
          self.currentPodcast = resu[0] as Podcasts
      } else {
          println("did not work")
      }
  }
  
      @IBAction func subscribe(sender: AnyObject) {
          for dict: AnyObject in episodesToDisplay {
      let episodesEntity = NSEntityDescription.entityForName("Episodes", inManagedObjectContext: self.managedContext)
      let episodesToSave = Episodes(entity: episodesEntity!, insertIntoManagedObjectContext: self.managedContext)
      var episodes = currentPodcast.episode.mutableCopy() as NSMutableOrderedSet
      let btDict = dict as NSDictionary &lt;---------------- Crash
          episodesToSave.title = btDict["title"] as String
          episodesToSave.summary = btDict["summary"] as String
          episodesToSave.link = btDict["link"] as String
          episodes.addObject(episodesToSave)
          currentPodcast.episode = episodes.copy() as NSOrderedSet
  
      }
  
  
  
      // Save
      var error:NSError?
      if !self.managedContext.save(&amp;error) {
          println("could not save \(error)")
      }
  }
  </code></pre>
  
  <p>Any ideas please?</p>