CoreDataStore

public class CoreDataStore : PersistenceStore

Implementation fo the PersistenceStore protocol using CoreData

  • Initialize a new CoreData persistence store

    Declaration

    Swift

    public init(context: NSManagedObjectContext)

    Parameters

    context

    The managed object context used for querying and

    Return Value

    An initialised instance of this class

  • Undocumented

    Declaration

    Swift

    public func fetchRequest(for type: Any.Type, predicate: NSPredicate) throws -> NSFetchRequest<NSFetchRequestResult>

  • Create a new object of the given type.

    Throws

    If a invalid type was specified

    Declaration

    Swift

    public func create<T>(type: Any.Type) throws -> T

    Parameters

    type

    The type of which a new object should be created

    Return Value

    A newly created object of the given type

  • Delete objects of the given type which also match the predicate.

    Throws

    If an invalid type was specified

    Declaration

    Swift

    public func delete(type: Any.Type, predicate: NSPredicate) throws

    Parameters

    type

    The type of which objects should be deleted

    predicate

    The predicate used for matching objects to delete

  • Fetches all objects of a specific type which also match the predicate.

    Throws

    If an invalid type was specified

    Declaration

    Swift

    public func fetchAll<T>(type: Any.Type, predicate: NSPredicate) throws -> [T]

    Parameters

    type

    The type of which objects should be fetched

    predicate

    The predicate used for matching object to fetch

    Return Value

    An array of matching objects

  • Declaration

    Swift

    public func fetchOne<T>(
        type: Any.Type,
        predicate: NSPredicate
    ) throws -> T
  • Returns an array of names of properties the given type stores persistently.

    This should omit any properties returned by relationshipsFor(type:).

    Throws

    If an invalid type was specified

    Declaration

    Swift

    public func properties(for type: Any.Type) throws -> [String]

    Parameters

    type

    The type of which properties should be returned for

    Return Value

    An array of property names representing system native types.

  • Returns an array of property names for any relationship the given type stores persistently.

    Throws

    If an invalid type was specified

    Declaration

    Swift

    public func relationships(for type: Any.Type) throws -> [String]

    Parameters

    type

    The type of which properties should be returned for

    Return Value

    An array of property names representing related entities.

  • Performs the actual save to the persistence store.

    Throws

    If any error occured during the save operation

    Declaration

    Swift

    public func save() throws
  • Remove persistence store and add a new one in its place WARNING: all the data will be wipes in the current persistence store associated with the NSManagedObjectContext

    Declaration

    Swift

    public func wipe() throws

Helper methods