Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/// A `NSManagedObject` that wants to be converted from an `ObjectConvertible` object should implement the `ManagedObjectConvertible` protocol.
protocol ManagedObjectConvertible {
/// An object which should implement the `ObjectConvertible` protocol.
associatedtype T
/// A String representing a URI that provides an archiveable reference to the object in Core Data.
var identifier: String? { get }
/// Insert an object in Core Data.
///
/// - Parameters:
/// - object: The object to insert.
/// - context: The managed object context.
static func insert(_ object: T, with context: NSManagedObjectContext)
/// Update an object in Core Data.
///
/// - Parameters:
/// - object: The object to update.
/// - context: The managed object context.
static func update(_ object: T, with context: NSManagedObjectContext)
/// Delete an object from Core Data.
///
/// - Parameters:
/// - object: The object to delete.
/// - context: The managed object context.
static func delete(_ object: T, with context: NSManagedObjectContext)
/// Fetch all objects from Core Data.
///
/// - Parameter context: The managed object context.
/// - Returns: A list of objects.
static func fetchAll(from context: NSManagedObjectContext) -> [T]
/// Set the managed object's parameters with an object's parameters.
///
/// - Parameter object: An object.
func from(object: T)
/// Create an object, populated with the managed object's properties.
///
/// - Returns: An object.
func toObject() -> T
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.