Skip to content

Instantly share code, notes, and snippets.

@nicol3a
Last active February 3, 2019 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicol3a/db957b7376a5b263defa75c53210721a to your computer and use it in GitHub Desktop.
Save nicol3a/db957b7376a5b263defa75c53210721a to your computer and use it in GitHub Desktop.
/// 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