All Projects → shaps80 → Stack

shaps80 / Stack

Licence: MIT license
A Type-Safe, Thread-Safe-ish approach to CoreData in Swift

Programming Languages

swift
15916 projects
shell
77523 projects
objective c
16641 projects - #2 most used programming language
c
50402 projects - #5 most used programming language
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Stack

cosmospy
Python tools for Cosmos wallet management and offline transaction signing
Stars: ✭ 57 (+21.28%)
Mutual labels:  transaction
Taskey
🚀 It Makes easy to track your task 🔥 Beautiful & Animated UI👨🏻‍💻 . Contributions are always welcome 🤗
Stars: ✭ 34 (-27.66%)
Mutual labels:  coredata
dtmcli-php
a php client for distributed transaction framework dtm.
Stars: ✭ 26 (-44.68%)
Mutual labels:  transaction
ViewControllersFactory
Instantiate your ViewControllers easily with this small factory class
Stars: ✭ 26 (-44.68%)
Mutual labels:  generics
neb.java
Java implementation of the Nebulas protocol
Stars: ✭ 30 (-36.17%)
Mutual labels:  transaction
bitcoincashjs
WARNING: This project is no longer maintained. Please, use bitcore-lib-cash instead.
Stars: ✭ 80 (+70.21%)
Mutual labels:  transaction
truthy
Package truthy provides truthy condition testing with Go generics
Stars: ✭ 31 (-34.04%)
Mutual labels:  generics
SwiftRadix
Easily convert integers to binary/hex/octal strings and back again with clean functional syntax.
Stars: ✭ 34 (-27.66%)
Mutual labels:  generics
eth.rb
a straightforward library to build, sign, and broadcast ethereum transactions anywhere you can run ruby.
Stars: ✭ 111 (+136.17%)
Mutual labels:  transaction
hermes-js
Universal action dispatcher for JavaScript apps
Stars: ✭ 15 (-68.09%)
Mutual labels:  transaction
heidi
heidi : tidy data in Haskell
Stars: ✭ 24 (-48.94%)
Mutual labels:  generics
ConfuserExPlugins
Transforms all types to generics, and all constructor calls and method calls into generic call factories.
Stars: ✭ 32 (-31.91%)
Mutual labels:  generics
nebPay.js
Nebulas payment Javascript SDK
Stars: ✭ 81 (+72.34%)
Mutual labels:  transaction
js-undo-manager
Simple JavaScript undo/redo command manager supporting transactions with no dependencies
Stars: ✭ 23 (-51.06%)
Mutual labels:  transaction
safe
🛡 PHP functions smarten up to throw exceptions instead of returning false or triggering errors.
Stars: ✭ 15 (-68.09%)
Mutual labels:  safety
SLazeKit
SLazeKit is a framework providing models mapper and CoreData serializer for RESTful resources.
Stars: ✭ 23 (-51.06%)
Mutual labels:  coredata
PlasmaContract
More Viable Plasma (MoreVP) contract with Limbo Exits
Stars: ✭ 26 (-44.68%)
Mutual labels:  transaction
core-data-model-description
Declarative way to describe a Core Data model in code.
Stars: ✭ 60 (+27.66%)
Mutual labels:  coredata
ttlcache
An in-memory cache with item expiration and generics
Stars: ✭ 468 (+895.74%)
Mutual labels:  generics
ts-mongodb-orm
Typescript Orm wrapper for Mongodb
Stars: ✭ 13 (-72.34%)
Mutual labels:  transaction

Stack Logo

Stack

CI Status Version Language Platform

Wouldn't it be great to have a type-safe CoreData Stack?

Reading

let stack = Stack.defaultStack()
let query = Query<Person>().sort(byKey: "name", direction: .Ascending).filter("name == %@", name)
let results = try! stack.fetch(query)
print(results.first?.name)

Writing

let stack = Stack.defaultStack()
stack.write({ (transaction) -> Void in
  let person = try transaction.fetchOrInsert("name", identifier: name) as Person
  person.age = 35
}, completion: nil)

Introducing Stack

CoreData is a powerful API, but its easily misused and misunderstood. Stack attempts to remove many of the issues associated with using CoreData in your applications.

Specifically, Stack adds both type-safety and thread-safety (ish) methods for dealing with queries and updates.

Additionally, Stack provides a much more expressive API through features like:

  • Type-safe inserts, updates and deletes
  • Query chaining
  • Custom Query class for setting up sorting, filtering, etc...
  • Transaction based API -- No access to contexts!
  • Asynchronous
  • Lightweight -- Swift function overloads allow the API to remain clean and concise
  • NSFetchedResultsController support -- convenience init()
  • See Documentation for more...

Goal

The aim of Stack is to provide a clean, expressive abstraction from CoreData. Giving you the flexibility and power of CoreData, without all the headache surrounding contexts and thread management.

With Swift, Stack now supports type-safe queries giving you more confidence when implementing CoreData in your applications.

Stack 2.0 provides read-only access through the Stack itself, moving all write methods into a transaction. This prevents you from making mistakes and attempting to update objects outside of a transaction.

Stack is used in various production apps, but I still consider it an ever changing concept so input is welcome :)

Need to Know

Reading

Once you have a Stack, reading is easy. You just need to construct a query and then call one of the fetch methods on your stack. Note: The optional is required since a fetch may return nil.

let stack = Stack.defaultStack()
let query= Query<Person>(key: "name", identifier: "Shaps")
let person = try! stack.fetch(query).first
print(person?.name)

Now we can update that same object. Note: Thanks to Swift closures, we can safely re-define the variable with the same name.

Writing

let stack = Stack.defaultStack()
stack.write({ (transaction) -> Void in
  let person = transaction.copy(person)
  person.age = 35
}, completion: nil)

As you can see, all write actions occur ONLY inside a transaction, which prevents many common mistakes when implementing CoreData.

You probably noticed that copy() function? This is another nice feature provided by Stack. Basically it will copy the object(s) into the current transaction/context so you don't try to modify an object on the wrong thread. And don't worry, all changes will be propogated to your other threads automatically ;)

Docs

To learn more about how to use Stack. Checkout the included example project, read over the unit tests or checkout the documentation.

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

Stack is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "Stack"

Author

Shaps, [email protected]

License

Stack is available under the MIT license. See the LICENSE file for more info.

Attribution

  • All code is my own, no 3rd party code is used in this project at all.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].