CoreDataHelper
public class CoreDataHelper
CoreDataHelper is used to perform basic level core data interaction.
Version
1.5.0Date
24/07/2019-
Get the singleton object.
Declaration
Swift
public static let standard: CoreDataHelper?
-
Initialize the object.
Declaration
Swift
public init?(modelName: String, bundle: Bundle = .main, fileManager: FileManager = .default)
Parameters
modelName
The name of the model.
bundle
The bundle that the model belongs to.
fileManager
The file system that hosts the model.
-
Prepare an object for inserting to the core data.
Declaration
Swift
public func object(of type: AnyClass) -> NSManagedObject
Parameters
type
The class of the object that need to be inserted.
Return Value
The object for insertion.
-
Get the object list of a specific class type of object.
Declaration
Swift
public func objects(of type: AnyClass, withCondition condition: String? = nil, withArguments arguments: [Any]? = nil) -> [NSManagedObject]?
Parameters
type
The type of class need to be retrieved.
condition
The condition of the object.
arguments
The list to be fit into the condition.
Return Value
A list of object. Nil will be returned if there has been an error.
-
Judge whether an object with spedific condition exists or not.
Declaration
Swift
public func isObjectExisted(of type: AnyClass, withCondition condition: String? = nil, withArguments arguments: [Any]? = nil) -> Bool?
Parameters
type
The type of class need to be retrieved.
condition
The condition of the object.
arguments
The list to be fit into the condition.
Return Value
Whether the object exists or not. Nil will be returned if there has been an error.
-
Delete a spedific object.
Declaration
Swift
@discardableResult public func delete(_ object: NSManagedObject) -> Bool?
Parameters
object
The object to be deleted.
Return Value
Whether the object has been deleted or not. Nil will be returned if there has been an error.
-
Delete all objects belonging to a specific class type.
Declaration
Swift
@discardableResult public func deleteObjects(of type: AnyClass) -> Bool?
Parameters
type
The type of objects should be deleted.
Return Value
Whether the object has been deleted or not. Nil will be returned if there has been an error.
-
Save any unsaved change.
Declaration
Swift
@discardableResult public func saveChanges() -> Bool?
Return Value
Whether new changes have been saved or not. Nil if there is an error.
-
Reset the context
Declaration
Swift
@discardableResult public func resetChanges() -> Bool
Return Value
Whether the context has been reseted or not.