Skip to content

Instantly share code, notes, and snippets.

@ennioma
Last active July 6, 2017 21:31
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 ennioma/5f3c6e372cad6968b37df2169ec1d393 to your computer and use it in GitHub Desktop.
Save ennioma/5f3c6e372cad6968b37df2169ec1d393 to your computer and use it in GitHub Desktop.
/*
Operations on context
*/
protocol StorageContext {
/*
Create a new object with default values
return an object that is conformed to the `Storable` protocol
*/
func create<T: Storable>(_ model: T.Type, completion: @escaping ((T) -> Void)) throws
/*
Save an object that is conformed to the `Storable` protocol
*/
func save(object: Storable) throws
/*
Update an object that is conformed to the `Storable` protocol
*/
func update(block: @escaping () -> ()) throws
/*
Delete an object that is conformed to the `Storable` protocol
*/
func delete(object: Storable) throws
/*
Delete all objects that are conformed to the `Storable` protocol
*/
func deleteAll<T: Storable>(_ model: T.Type) throws
/*
Return a list of objects that are conformed to the `Storable` protocol
*/
func fetch<T: Storable>(_ model: T.Type, predicate: NSPredicate?, sorted: Sorted?, completion: (([T]) -> ()))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment