AERecord

public class AERecord

This class is facade for accessing shared instance of AEStack (private class which is all about the Core Data Stack).

  • Managed object context for current thread.

    Declaration

    Swift

    public class var defaultContext: NSManagedObjectContext { return AEStack.sharedInstance.defaultContext }
  • Managed object context for main thread.

    Declaration

    Swift

    public class var mainContext: NSManagedObjectContext { return AEStack.sharedInstance.mainContext }
  • Managed object context for background thread.

    Declaration

    Swift

    public class var backgroundContext: NSManagedObjectContext { return AEStack.sharedInstance.backgroundContext }
  • Persistent Store Coordinator for current stack.

    Declaration

    Swift

    public class var persistentStoreCoordinator: NSPersistentStoreCoordinator? { return AEStack.sharedInstance.persistentStoreCoordinator }
  • Returns the final URL in Application Documents Directory for the store with given name.

    :param: name Filename for the store.

    Declaration

    Swift

    public class func storeURLForName(name: String) -> NSURL
  • Returns merged model from the bundle for given class.

    :param: forClass Class inside bundle with data model.

    Declaration

    Swift

    public class func modelFromBundle(forClass forClass: AnyClass) -> NSManagedObjectModel
  • Loads Core Data Stack (creates new if it doesn’t already exist) with given options (all options are optional).

    • Default option for managedObjectModel is NSManagedObjectModel.mergedModelFromBundles(nil)!.
    • Default option for storeType is NSSQLiteStoreType.
    • Default option for storeURL is bundleIdentifier + ".sqlite" inside applicationDocumentsDirectory.

    :param: managedObjectModel Managed object model for Core Data Stack. :param: storeType Store type for Persistent Store creation. :param: configuration Configuration for Persistent Store creation. :param: storeURL URL for Persistent Store creation. :param: options Options for Persistent Store creation.

    :returns: Throws error if something went wrong.

    Declaration

    Swift

    public class func loadCoreDataStack(
            managedObjectModel managedObjectModel: NSManagedObjectModel = AEStack.defaultModel,
            storeType: String = NSSQLiteStoreType,
            configuration: String? = nil,
            storeURL: NSURL = AEStack.defaultURL,
            options: [NSObject : AnyObject]? = nil) throws
  • Destroys Core Data Stack for given store URL (stop notifications, reset contexts, remove persistent store and delete .sqlite file). This action can’t be undone.

    :param: storeURL Store URL for stack to destroy.

    :returns: Throws error if something went wrong.

    Declaration

    Swift

    public class func destroyCoreDataStack(storeURL: NSURL = AEStack.defaultURL) throws
  • Deletes all records from all entities contained in the model.

    :param: context If not specified, defaultContext will be used.

    Declaration

    Swift

    public class func truncateAllData(context: NSManagedObjectContext? = nil)
  • Executes given fetch request.

    :param: request Fetch request to execute. :param: context If not specified, defaultContext will be used.

    Declaration

    Swift

    public class func executeFetchRequest(request: NSFetchRequest, context: NSManagedObjectContext? = nil) -> [NSManagedObject]
  • Saves context (without waiting - returns immediately).

    :param: context If not specified, defaultContext will be used.

    Declaration

    Swift

    public class func saveContext(context: NSManagedObjectContext? = nil)
  • Saves context with waiting (returns when context is saved).

    :param: context If not specified, defaultContext will be used.

    Declaration

    Swift

    public class func saveContextAndWait(context: NSManagedObjectContext? = nil)
  • Turns objects into faults for given Array of NSManagedObjectID.

    :param: objectIDS Array of NSManagedObjectID objects to turn into fault. :param: mergeChanges A Boolean value. :param: context If not specified, defaultContext will be used.

    Declaration

    Swift

    public class func refreshObjects(objectIDS objectIDS: [NSManagedObjectID], mergeChanges: Bool, context: NSManagedObjectContext = AERecord.defaultContext)
  • Turns all registered objects into faults.

    :param: mergeChanges A Boolean value. :param: context If not specified, defaultContext will be used.

    Declaration

    Swift

    public class func refreshAllRegisteredObjects(mergeChanges mergeChanges: Bool, context: NSManagedObjectContext = AERecord.defaultContext)