tie / Roku

CoreData's concurrent stacks made easy.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Warning: This project no longer maintained. Consider using NSPersistentContainer.

Roku ()

CoreData's concurrent stacks made easy.

Inspired by Concurrent Core Data Stacks article, WWDC2013 Session 211 and Seru CoreData stack by [kostiakoval].

Usage

Note: Roku has a set of flexible protocols for building stacks but I have not documented the usage of them yet.

import Roku

Initialize StorageModel with a function that creates a new coordinator:

func newPersistentStoreCoordinator() -> NSPersistentStoreCoordinator {
    // Create and return new persistent store coordinator
}

let storage = StorageModel(persistentStoreCoordinator: newPersistentStoreCoordinator())

or migrate an existing persistent store coordinator.

let storage = StorageModel(persistentStoreCoordinator: oldPersistentStoreCoordinator)

Initialize Roku stack with a base stack:

let baseStack = Roku<StackBase>(storage: storage)

or with a nested stack...

let nestedStack = Roku<NestedStackBase>(storage: storage)

or with an independent stack...

let independentStack = Roku<IndependentStackBase>(storage: storage)

or with a custom stack that conforms to StackProtocol and StorageModelContainer protocols.

let myAwesomeStack = Roku<AwesomeStack>(storage: storage)

Enjoy Roku's features 🎉

myStack.withBackgroundContext { context in
    // Do heavy import operations on the background context
}

myStack.persist { error -> Bool in
    // Handle an error

    // If error was successfully handled,
    // `Roku` will repeat save.
    return errorHandled && shouldRepeatSave
}

// Managed object context with main queue concurrency type
myStack.mainObjectContext

// Get `StorageModel` from encapsulated stack
let storage = myStack.withUnderlyingStack { (inout stack: ContextStack) in
    return stack.storage
}

TODO

  • Implement observable NSManagedObjectContext.
  • Implement templates and default implementations.
  • Implement all functionality of Roku class.
  • Finish writing README.md file.
  • Add examples of custom stack templates and implementations.
  • Feature: implement manager for stack with multiple persistent store coordinators.
  • Continuous integration.

License

Available under the MIT license. See license file for more info.

About

CoreData's concurrent stacks made easy.

License:MIT License


Languages

Language:Swift 100.0%