Skip to content
This repository has been archived by the owner on Feb 19, 2018. It is now read-only.
/ Roku Public archive

CoreData's concurrent stacks made easy.

License

Notifications You must be signed in to change notification settings

tie/Roku

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages