NSManagedObject

Undocumented

  • This property must return correct entity name because it’s used all across other helpers to reference custom NSManagedObject subclass.

    You may override this property in your custom NSManagedObject subclass if needed (but it should work out of the box generally).

    Declaration

    Swift

    class var entityName: String
  • An NSEntityDescription object describes an entity in Core Data.

    Declaration

    Swift

    class var entity: NSEntityDescription?
  • Creates fetch request (for any entity type) for given predicate and sort descriptors (which are optional).

    :param: predicate Predicate for fetch request. :param sortDescriptors Sort Descriptors for fetch request.

    :returns: The created fetch request.

    Declaration

    Swift

    class func createFetchRequest(predicate predicate: NSPredicate? = nil, sortDescriptors: [NSSortDescriptor]? = nil) -> NSFetchRequest
  • Creates predicate for given attributes and predicate type.

    :param: attributes Dictionary of attribute names and values. :param: predicateType If not specified, .AndPredicateType will be used.

    :returns: The created predicate.

    Declaration

    Swift

    class func createPredicateForAttributes(attributes: [NSObject : AnyObject], predicateType: NSCompoundPredicateType = defaultPredicateType) -> NSPredicate
  • Creates new instance of entity object.

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

    :returns: New instance of Self.

    Declaration

    Swift

    class func create(context context: NSManagedObjectContext = AERecord.defaultContext) -> Self
  • Creates new instance of entity object and set it with given attributes.

    :param: attributes Dictionary of attribute names and values. :param: context If not specified, defaultContext will be used.

    :returns: New instance of Self with set attributes.

    Declaration

    Swift

    class func createWithAttributes(attributes: [String : AnyObject], context: NSManagedObjectContext = AERecord.defaultContext) -> Self
  • Finds the first record for given attribute and value or creates new if the it does not exist.

    :param: attribute Attribute name. :param: value Attribute value. :param: context If not specified, defaultContext will be used.

    :returns: Instance of managed object.

    Declaration

    Swift

    class func firstOrCreateWithAttribute(attribute: String, value: AnyObject, context: NSManagedObjectContext = AERecord.defaultContext) -> NSManagedObject
  • Finds the first record for given attributes or creates new if the it does not exist.

    :param: attributes Dictionary of attribute names and values. :param: predicateType If not specified, .AndPredicateType will be used. :param: context If not specified, defaultContext will be used.

    :returns: Instance of managed object.

    Declaration

    Swift

    class func firstOrCreateWithAttributes(attributes: [String : AnyObject], predicateType: NSCompoundPredicateType = defaultPredicateType, context: NSManagedObjectContext = AERecord.defaultContext) -> NSManagedObject
  • Finds the first record.

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

    :returns: Optional managed object.

    Declaration

    Swift

    class func first(sortDescriptors sortDescriptors: [NSSortDescriptor]? = nil, context: NSManagedObjectContext = AERecord.defaultContext) -> NSManagedObject?
  • Finds the first record for given predicate.

    :param: predicate Predicate. :param: sortDescriptors Sort descriptors. :param: context If not specified, defaultContext will be used.

    :returns: Optional managed object.

    Declaration

    Swift

    class func firstWithPredicate(predicate: NSPredicate, sortDescriptors: [NSSortDescriptor]? = nil, context: NSManagedObjectContext = AERecord.defaultContext) -> NSManagedObject?
  • Finds the first record for given attribute and value.

    :param: attribute Attribute name. :param: value Attribute value. :param: sortDescriptors Sort descriptors. :param: context If not specified, defaultContext will be used.

    :returns: Optional managed object.

    Declaration

    Swift

    class func firstWithAttribute(attribute: String, value: AnyObject, sortDescriptors: [NSSortDescriptor]? = nil, context: NSManagedObjectContext = AERecord.defaultContext) -> NSManagedObject?
  • Finds the first record for given attributes.

    :param: attributes Dictionary of attribute names and values. :param: predicateType If not specified, .AndPredicateType will be used. :param: sortDescriptors Sort descriptors. :param: context If not specified, defaultContext will be used.

    :returns: Optional managed object.

    Declaration

    Swift

    class func firstWithAttributes(attributes: [NSObject : AnyObject], predicateType: NSCompoundPredicateType = defaultPredicateType, sortDescriptors: [NSSortDescriptor]? = nil, context: NSManagedObjectContext = AERecord.defaultContext) -> NSManagedObject?
  • Finds the first record ordered by given attribute.

    :param: name Attribute name. :param: ascending A Boolean value. :param: context If not specified, defaultContext will be used.

    :returns: Optional managed object.

    Declaration

    Swift

    class func firstOrderedByAttribute(name: String, ascending: Bool = true, context: NSManagedObjectContext = AERecord.defaultContext) -> NSManagedObject?
  • Finds all records.

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

    :returns: Optional managed object.

    Declaration

    Swift

    class func all(sortDescriptors: [NSSortDescriptor]? = nil, context: NSManagedObjectContext = AERecord.defaultContext) -> [NSManagedObject]?
  • Finds all records for given predicate.

    :param: predicate Predicate. :param: sortDescriptors Sort descriptors. :param: context If not specified, defaultContext will be used.

    :returns: Optional managed object.

    Declaration

    Swift

    class func allWithPredicate(predicate: NSPredicate, sortDescriptors: [NSSortDescriptor]? = nil, context: NSManagedObjectContext = AERecord.defaultContext) -> [NSManagedObject]?
  • Finds all records for given attribute and value.

    :param: attribute Attribute name. :param: value Attribute value. :param: sortDescriptors Sort descriptors. :param: context If not specified, defaultContext will be used.

    :returns: Optional managed object.

    Declaration

    Swift

    class func allWithAttribute(attribute: String, value: AnyObject, sortDescriptors: [NSSortDescriptor]? = nil, context: NSManagedObjectContext = AERecord.defaultContext) -> [NSManagedObject]?
  • Finds all records for given attributes.

    :param: attributes Dictionary of attribute names and values. :param: predicateType If not specified, .AndPredicateType will be used. :param: sortDescriptors Sort descriptors. :param: context If not specified, defaultContext will be used.

    :returns: Optional managed object.

    Declaration

    Swift

    class func allWithAttributes(attributes: [NSObject : AnyObject], predicateType: NSCompoundPredicateType = defaultPredicateType, sortDescriptors: [NSSortDescriptor]? = nil, context: NSManagedObjectContext = AERecord.defaultContext) -> [NSManagedObject]?
  • Deletes instance of entity object.

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

    Declaration

    Swift

    func deleteFromContext(context: NSManagedObjectContext = AERecord.defaultContext)
  • Deletes all records.

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

    Declaration

    Swift

    class func deleteAll(context context: NSManagedObjectContext = AERecord.defaultContext)
  • Deletes all records for given predicate.

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

    Declaration

    Swift

    class func deleteAllWithPredicate(predicate: NSPredicate, context: NSManagedObjectContext = AERecord.defaultContext)
  • Deletes all records for given attribute name and value.

    :param: attribute Attribute name. :param: value Attribute value. :param: context If not specified, defaultContext will be used.

    Declaration

    Swift

    class func deleteAllWithAttribute(attribute: String, value: AnyObject, context: NSManagedObjectContext = AERecord.defaultContext)
  • Deletes all records for given attributes.

    :param: attributes Dictionary of attribute names and values. :param: predicateType If not specified, .AndPredicateType will be used. :param: context If not specified, defaultContext will be used.

    Declaration

    Swift

    class func deleteAllWithAttributes(attributes: [NSObject : AnyObject], predicateType: NSCompoundPredicateType = defaultPredicateType, context: NSManagedObjectContext = AERecord.defaultContext)
  • Counts all records.

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

    :returns: Count of records.

    Declaration

    Swift

    class func count(context: NSManagedObjectContext = AERecord.defaultContext) -> Int
  • Counts all records for given predicate.

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

    :returns: Count of records.

    Declaration

    Swift

    class func countWithPredicate(predicate: NSPredicate? = nil, context: NSManagedObjectContext = AERecord.defaultContext) -> Int
  • Counts all records for given attribute name and value.

    :param: attribute Attribute name. :param: value Attribute value. :param: context If not specified, defaultContext will be used.

    :returns: Count of records.

    Declaration

    Swift

    class func countWithAttribute(attribute: String, value: AnyObject, context: NSManagedObjectContext = AERecord.defaultContext) -> Int
  • Counts all records for given attributes.

    :param: attributes Dictionary of attribute names and values. :param: predicateType If not specified, .AndPredicateType will be used. :param: context If not specified, defaultContext will be used.

    :returns: Count of records.

    Declaration

    Swift

    class func countWithAttributes(attributes: [NSObject : AnyObject], predicateType: NSCompoundPredicateType = defaultPredicateType, context: NSManagedObjectContext = AERecord.defaultContext) -> Int
  • Gets distinct values for given attribute and predicate.

    :param: attribute Attribute name. :param: predicate Predicate. :param: sortDescriptors Sort descriptors. :param: context If not specified, defaultContext will be used.

    :returns: Throws optional Array of AnyObject.

    Declaration

    Swift

    class func distinctValuesForAttribute(attribute: String, predicate: NSPredicate? = nil, sortDescriptors: [NSSortDescriptor]? = nil, context: NSManagedObjectContext = AERecord.defaultContext) throws -> [AnyObject]?
  • Gets distinct values for given attributes and predicate.

    :param: attributes Dictionary of attribute names and values. :param: predicate Predicate. :param: sortDescriptors Sort descriptors. :param: context If not specified, defaultContext will be used.

    :returns: Throws optional Array of AnyObject.

    Declaration

    Swift

    class func distinctRecordsForAttributes(attributes: [String], predicate: NSPredicate? = nil, sortDescriptors: [NSSortDescriptor]? = nil, context: NSManagedObjectContext = AERecord.defaultContext) throws -> [Dictionary<String, AnyObject>]?
  • Gets next ID for given attribute name. Attribute must be of Int type.

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

    :returns: Auto incremented ID.

    Declaration

    Swift

    class func autoIncrementedIntegerAttribute(attribute: String, context: NSManagedObjectContext = AERecord.defaultContext) -> Int
  • Turns object into fault.

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

    Declaration

    Swift

    func refresh(mergeChanges: Bool = true, context: NSManagedObjectContext = AERecord.defaultContext)
  • Updates data directly in persistent store (iOS 8 and above).

    :param: predicate Predicate. :param: properties Properties to update. :param: resultType If not specified, StatusOnlyResultType will be used. :param: context If not specified, defaultContext will be used.

    :returns: Batch update result.

    Declaration

    Swift

    class func batchUpdate(predicate predicate: NSPredicate? = nil, properties: [NSObject : AnyObject]? = nil, resultType: NSBatchUpdateRequestResultType = .StatusOnlyResultType, context: NSManagedObjectContext = AERecord.defaultContext) -> NSBatchUpdateResult?
  • Updates data directly in persistent store (iOS 8 and above).

    :param: predicate Predicate. :param: properties Properties to update. :param: context If not specified, defaultContext will be used.

    :returns: Count of updated objects.

    Declaration

    Swift

    class func objectsCountForBatchUpdate(predicate: NSPredicate? = nil, properties: [NSObject : AnyObject]? = nil, context: NSManagedObjectContext = AERecord.defaultContext) -> Int
  • Updates data directly in persistent store (iOS 8 and above).

    Objects are turned into faults after updating (managed object context is refreshed).

    :param: predicate Predicate. :param: properties Properties to update. :param: context If not specified, defaultContext will be used.

    Declaration

    Swift

    class func batchUpdateAndRefreshObjects(predicate: NSPredicate? = nil, properties: [NSObject : AnyObject]? = nil, context: NSManagedObjectContext = AERecord.defaultContext)