Contact Us

Use the form on the right to contact us.

You can edit the text in this area, and change where the contact form on the right submits to, by entering edit mode using the modes on the bottom right. 


Oak Ridge, TN, 37830
United States

Swift-Snips

Using only one managedObjectContext

Wade Cantley

The problem is that when using the default setup for managedObjectContext, working with multiple core data MOC systems means dropping and re-instantiating the MOC.  But here is some code that prevents that so that it checks for the MOC first before creating a new one.

Located in AppDelegate.swift
Use this in place of the default.


    var managedObjectContext: NSManagedObjectContext {
       
        if (_managedObjectContext != nil)
        {
            return _managedObjectContext!; // making sure you don't reinitialise
        }
        let coordinator = self.persistentStoreCoordinator
       
        _managedObjectContext = NSManagedObjectContext(concurrencyType: NSManagedObjectContextConcurrencyType.PrivateQueueConcurrencyType)
        _managedObjectContext!.persistentStoreCoordinator = coordinator
       
       
        return _managedObjectContext!
    }