{"id":16482759,"url":"https://github.com/shaps80/stack","last_synced_at":"2025-03-21T07:30:48.488Z","repository":{"id":27013272,"uuid":"30477540","full_name":"shaps80/Stack","owner":"shaps80","description":"A Type-Safe, Thread-Safe-ish approach to CoreData in Swift","archived":false,"fork":false,"pushed_at":"2016-08-29T16:15:27.000Z","size":603,"stargazers_count":48,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-17T22:36:55.141Z","etag":null,"topics":["coredata","database","generics","ios","orm","safety","sql","swift","transaction"],"latest_commit_sha":null,"homepage":"http://shaps.me/blog/stack","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shaps80.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-08T02:00:34.000Z","updated_at":"2023-04-14T17:51:56.000Z","dependencies_parsed_at":"2022-08-31T13:53:35.784Z","dependency_job_id":null,"html_url":"https://github.com/shaps80/Stack","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaps80%2FStack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaps80%2FStack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaps80%2FStack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaps80%2FStack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shaps80","download_url":"https://codeload.github.com/shaps80/Stack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244757290,"owners_count":20505367,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coredata","database","generics","ios","orm","safety","sql","swift","transaction"],"created_at":"2024-10-11T13:11:55.467Z","updated_at":"2025-03-21T07:30:48.188Z","avatar_url":"https://github.com/shaps80.png","language":"Swift","readme":"\u003cimg src=\"assets/stack.png\" width=128 height=128 alt=\"Stack Logo\" /\u003e\n\n# Stack\n\n[![CI Status](http://img.shields.io/travis/shaps80/Stack.svg?style=flat)](https://travis-ci.org/shaps80/Stack)\n[![Version](https://img.shields.io/cocoapods/v/Stack.svg?style=flat)](http://cocoadocs.org/docsets/Stack)\n[![Language](https://img.shields.io/badge/language-swift-ff69b4.svg)](http://cocoadocs.org/docsets/Stack)\n[![Platform](https://img.shields.io/cocoapods/p/Stack.svg?style=flat)](http://cocoadocs.org/docsets/Stack)\n\nWouldn't it be great to have a type-safe CoreData Stack?\n\n__Reading__\n\n```swift\nlet stack = Stack.defaultStack()\nlet query = Query\u003cPerson\u003e().sort(byKey: \"name\", direction: .Ascending).filter(\"name == %@\", name)\nlet results = try! stack.fetch(query)\nprint(results.first?.name)\n```\n\n__Writing__\n\n```swift\nlet stack = Stack.defaultStack()\nstack.write({ (transaction) -\u003e Void in\n  let person = try transaction.fetchOrInsert(\"name\", identifier: name) as Person\n  person.age = 35\n}, completion: nil)\n```\n\n## Introducing Stack\n\nCoreData 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.\n\nSpecifically, Stack adds both type-safety and thread-safety (ish) methods for dealing with queries and updates.\n\nAdditionally, Stack provides a much more expressive API through features like:\n\n* Type-safe inserts, updates and deletes\n* Query chaining\n* Custom Query class for setting up sorting, filtering, etc...\n* Transaction based API -- No access to contexts!\n* Asynchronous\n* Lightweight -- Swift function overloads allow the API to remain clean and concise\n* NSFetchedResultsController support -- convenience init()\n* See [Documentation](http://cocoadocs.org/docsets/Stack/2.0.0) for more...\n\n## Goal\n\nThe 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.\n\nWith Swift, Stack now supports type-safe queries giving you more confidence when implementing CoreData in your applications.\n\nStack 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.\n\nStack is used in various production apps, but I still consider it an ever changing concept so input is welcome :)\n\n## Need to Know\n\n__Reading__\n\nOnce 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.\n\n```swift\nlet stack = Stack.defaultStack()\nlet query= Query\u003cPerson\u003e(key: \"name\", identifier: \"Shaps\")\nlet person = try! stack.fetch(query).first\nprint(person?.name)\n```\n\nNow we can update that same object. Note: Thanks to Swift closures, we can safely re-define the variable with the same name.\n\n__Writing__\n\n```swift\nlet stack = Stack.defaultStack()\nstack.write({ (transaction) -\u003e Void in\n  let person = transaction.copy(person)\n  person.age = 35\n}, completion: nil)\n```\n\nAs you can see, all write actions occur ONLY inside a transaction, which prevents many common mistakes when implementing CoreData. \n\nYou 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 ;)\n\n## Docs\n\nTo learn more about how to use Stack. Checkout the included example project, read over the unit tests or checkout the [documentation](https://github.com/shaps80/Stack/wiki).\n\n## Usage\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\t\n\n## Installation\n\nStack is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\npod \"Stack\"\n\n## Author\n\nShaps, shapsuk@me.com\n\n## License\n\nStack is available under the MIT license. See the LICENSE file for more info.\n\n## Attribution\n\n* All code is my own, no 3rd party code is used in this project at all. \n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshaps80%2Fstack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshaps80%2Fstack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshaps80%2Fstack/lists"}