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
modelNameThe name of the model.
bundleThe bundle that the model belongs to.
fileManagerThe file system that hosts the model.
-
Prepare an object for inserting to the core data.
Declaration
Swift
public func object(of type: AnyClass) -> NSManagedObjectParameters
typeThe 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
typeThe type of class need to be retrieved.
conditionThe condition of the object.
argumentsThe 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
typeThe type of class need to be retrieved.
conditionThe condition of the object.
argumentsThe 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
objectThe 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
typeThe 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() -> BoolReturn Value
Whether the context has been reseted or not.
CoreDataHelper Class Reference