fetching from CloudKit and saving to CoreData
<p>this is going to be a really noob question but I'm trying to get my app to download data from CloudKit and then save it to CoreData. </p>

<p>When I run this type of code, I get the following error. I'm really noob at CoreData, so this has been hard for me to understand. I think it has something to do with the way I'm dispatching the requests, but I'm not sure how I'm supposed to fix it. The error I get is:</p>

<blockquote>
  <p>Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'recordChangeSnapshot:forObjectID:: global ID may not be temporary when recording
  '</p>
</blockquote>

<p>Anyone have any ideas?</p>

<pre><code>import UIKit
import CloudKit
import CoreData

class Start: UIViewController {

    var classroomEN: String?
    var classroomTC: String?
    var classroomSC: String?

    var videos = [NSManagedObject]()

    override func viewDidLoad() {

        fetchData()
        fetchDataTC()
    }

    func fetchData() {

        //added to fetch data from CloudKit
        let container = CKContainer.defaultContainer()
        let publicData = container.publicCloudDatabase

        let predicate = NSPredicate(value: true)

        let queryEN = CKQuery(recordType: "ClassroomFAQEN", predicate: predicate)
        let queryTC = CKQuery(recordType: "ClassroomFAQTC", predicate: predicate)

        queryEN.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
        queryTC.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]

        publicData.performQuery(queryEN, inZoneWithID: nil) { results, error in

            if error == nil { // There is no error

                for entry in results! {
                    let newFAQ = classFAQ()
                    newFAQ.title = entry["Title"] as! String
                    newFAQ.content = entry["Content"] as! String
                    if entry["Picture"] != nil {
                        print("There is no picture")
                        newFAQ.picture = entry["Picture"] as! String
                    }
                    if entry["Video"] != nil {
                        print("There is no video")
                        newFAQ.video = entry["Video"] as! String
                    }

                    let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
                    let managedContext = appDelegate.managedObjectContext
                    let entity =  NSEntityDescription.entityForName("ClassroomFAQEN", inManagedObjectContext:managedContext)
                    let video = NSManagedObject(entity: entity!, insertIntoManagedObjectContext: managedContext)
                    video.setValue(newFAQ.title, forKey: "title")
                    video.setValue(newFAQ.content, forKey: "content")
                    video.setValue(newFAQ.picture, forKey: "picture")
                    video.setValue(newFAQ.video, forKey: "video")

                    do {
                        try video.managedObjectContext!.save()
                        self.videos.append(video)
                    } catch let error as NSError  {
                        print("Could not save \(error), \(error.userInfo)")
                    }

                    dispatch_async(dispatch_get_main_queue(), { () -&gt; Void in
                        print("Reloading data in tableView")
                        self.fetchDataTC()
                    })
                }
            }
            else {
                print(error)
            }
        }
    }

    func fetchDataTC() {

        //added to fetch data from CloudKit
        let container = CKContainer.defaultContainer()
        let publicData = container.publicCloudDatabase

        let predicate = NSPredicate(value: true)

        let queryEN = CKQuery(recordType: "ClassroomFAQEN", predicate: predicate)
        let queryTC = CKQuery(recordType: "ClassroomFAQTC", predicate: predicate)

        queryEN.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
        queryTC.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]

        publicData.performQuery(queryTC, inZoneWithID: nil) { results, error in

            if error == nil { // There is no error

                for entry in results! {
                    let newFAQ = classFAQ()
                    newFAQ.title = entry["Title"] as! String
                    newFAQ.content = entry["Content"] as! String
                    if entry["Picture"] != nil {
                        print("There is no picture")
                        newFAQ.picture = entry["Picture"] as! String
                    }
                    if entry["Video"] != nil {
                        print("There is no video")
                        newFAQ.video = entry["Video"] as! String
                    }

                    let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
                    let managedContext = appDelegate.managedObjectContext
                    let entity =  NSEntityDescription.entityForName("ClassroomFAQTC", inManagedObjectContext:managedContext)
                    let video = NSManagedObject(entity: entity!, insertIntoManagedObjectContext: managedContext)
                    video.setValue(newFAQ.title, forKey: "title")
                    video.setValue(newFAQ.content, forKey: "content")
                    video.setValue(newFAQ.picture, forKey: "picture")
                    video.setValue(newFAQ.video, forKey: "video")

                    do {
                        try video.managedObjectContext!.save()
                        self.videos.append(video)
                    } catch let error as NSError  {
                        print("Could not save \(error), \(error.userInfo)")
                    }

                    dispatch_async(dispatch_get_main_queue(), { () -&gt; Void in
                        print("Reloading data in tableView")
                    })
                }
            }
            else {
                print(error)
            }
        }

    }
</code></pre>