{"id":22050124,"url":"https://github.com/icapps/ios-duvel","last_synced_at":"2025-03-23T15:15:48.672Z","repository":{"id":56909189,"uuid":"60686862","full_name":"icapps/ios-duvel","owner":"icapps","description":"Using Core Data has never been easier with the Duvel cocoapod.","archived":false,"fork":false,"pushed_at":"2016-10-05T11:28:46.000Z","size":576,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-01T20:47:14.185Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/icapps.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2016-06-08T09:40:58.000Z","updated_at":"2016-06-27T10:26:27.000Z","dependencies_parsed_at":"2022-11-29T13:20:30.614Z","dependency_job_id":null,"html_url":"https://github.com/icapps/ios-duvel","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icapps%2Fios-duvel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icapps%2Fios-duvel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icapps%2Fios-duvel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icapps%2Fios-duvel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/icapps","download_url":"https://codeload.github.com/icapps/ios-duvel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245119592,"owners_count":20563763,"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":[],"created_at":"2024-11-30T14:17:57.514Z","updated_at":"2025-03-23T15:15:48.651Z","avatar_url":"https://github.com/icapps.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"![](Resources/Duvel.jpg)\n\n[![CI Status](http://img.shields.io/travis/icapps/ios-duvel.svg?style=flat)](https://travis-ci.org/icapps/ios-duvel)\n[![License](https://img.shields.io/cocoapods/l/Duvel.svg?style=flat)](http://cocoapods.org/pods/Duvel)\n[![Platform](https://img.shields.io/cocoapods/p/Duvel.svg?style=flat)](http://cocoapods.org/pods/Duvel)\n[![Version](https://img.shields.io/cocoapods/v/Duvel.svg?style=flat)](http://cocoapods.org/pods/Duvel)\n[![Language Swift 3.0](https://img.shields.io/badge/Language-Swift%203.0-orange.svg?style=flat)](https://swift.org)\n\n\u003e Duvel makes using Core Data more friendlier than ever with Swift.\n\n## TOC\n\n- [Installation](#installation)\n- [Features](#features)\n  - [Initialize](#initialize)\n  - [Context](#context)\n  - [Creation](#creation)\n  - [Deletion](#deletion)\n  - [Fetching](#fetching)\n  - [Saving](#saving)\n- [Bucket List](#bucket-list)\n- [Author](#author)\n- [License](#license)\n\n## Installation\n\nDuvel is available through [CocoaPods](http://cocoapods.org). To install it, simply add the following line to your `Podfile`:\n\n```ruby\npod 'Duvel', '~\u003e 1.0'\n```\n\n## Features\n\n### Initialize\n\nInitialize the usage of `Duvel` by using a `Duvel` instance. When initializing the instance you will create the persistent store.\n\n```swift\n// Create the default store.\nlet duvel = try! Duvel()\n\n// Create an in memory store.\nlet duvel = try! Duvel(storeType: NSInMemoryStoreType)\n\n// Create a store with a custom managed object model.\nlet managedObjectModel = NSManagedObjectModel.mergedModelFromBundles(nil)\nlet duvel = try! Duvel(managedObjectModel: managedObjectModel)\n```\n\nIs you want to instantiate `Duvel` with a static `shared` function that you want to use throughout your application without passing the instance between the different classes. Than extend `Duvel` like this.\n\n```swift\nextension Duvel {\n    static var shared: Duvel? = {\n        // Add more configuration to the instance as shown in the above code.\n        return try? Duvel()\n    }()\n}\n\n// This will encapsulate `Duvel` in an singleton instance.\nDuvel.shared\n```\n\n### Context\n\nThere are three ways to access some contexts.\n\n```swift\n// Get the main `NSManagedObjectContext`.\nDuvel.shared.mainContext\n\n// Get the background `NSManagedObjectContext`.\nDuvel.shared.backgroundContext\n\n// Get the `NSManagedObjectContext` for the current thread.\nDuvel.shared.currentContext\n```\n\nChanges made on the `backgroundContext` are automatically merged to the `mainContext` when succeeded.\n\n### Creation\n\nYou can create a `NSManagedObject` in a context. The `NSManagedObject` you want to create has to conform to the `ManagedObjectType` protocol. In this case `SomeManagedObject` conforms to `ManagedObjectType`.\n\n```swift\nlet context: NSManagedObjectContext = ...\nlet object = SomeManagedObject.create(in: context)\n```\n\nWe can also immediately set the properties during the creation process.\n\n```swift\nlet context: NSManagedObjectContext = ...\nlet object = SomeManagedObject.create(in: context) { innerObject in\n  innerObject.name = \"Leroy\"\n}\n```\n\n**BE AWARE!** Nothing is persisted to the store until you save.\n\n### Deletion\n\nThere is a possibility to delete all the `NSManagedObject`'s depending on the given `NSPredicate`. When no predicate is given we delete all the objects for the given type.\n\n```swift\nlet context: NSManagedObjectContext = ...\n\n// Delete all the objects.\nSomeManagedObject.deleteAll(in: context)\n\n// Delete the objects that match a predicate.\nlet predicate: NSPredicate = ...\nSomeManagedObject.deleteAll(in: context, with: predicate)\n\n// Delete one the object.\nlet object: SomeManagedObject = ...\nobject.delete(inContext: context)\n```\n\nIf you just want to delete a single object, you can use the one defined in Core Data.\n\n```swift\nlet context: NSManagedObjectContext = ...\nSomeManagedObject.deleteObject(in: context)\n```\n\n**BE AWARE!** Nothing is persisted to the store until you save.\n\n### Fetching\n\nFetch the first `NSManagedObject` depending on the value of the attribute.\n\nWhen no object was found for this value, you can create a new one with the attribute set to the given value. This will be done when the `createIfNeeded` parameter is set to true.\n\n```swift\nlet context: NSManagedObjectContext = ...\nlet object = SomeManagedObject.first(in: context, with: \"name\", value: \"Leroy\")\nlet object = SomeManagedObject.first(in: context, with: \"name\", value: \"Leroy\", createIfNeeded: true)\n```\n\nYou can also look for the first `NSManagedObject` found for the given predicate. You can also indicate the sort order of the fetched results so that you can eventually fetch the last object.\n\n```swift\nlet predicate: NSPredicate = ...\nlet descriptors: [NSSortDescriptor] = ...\nlet context: NSManagedObjectContext = ...\nlet object = SomeManagedObject.first(in: context, with: predicate, sort: descriptors)\n```\n\nFetch all the objects for a certain type. You can specify a filter by giving an `NSPredicate` and a sort order by providing a list of `NSSortDescriptor`'s.\n\n```swift\nlet predicate: NSPredicate = ...\nlet descriptors: [NSSortDescriptor] = ...\nlet context: NSManagedObjectContext = ...\nlet objects = SomeManagedObject.all(in: context, with: predicate, sort: descriptors)\n```\n\nCount the number of object. You can specify a filter by giving an `NSPredicate`.\n\n```swift\nlet predicate: NSPredicate = ...\nlet context: NSManagedObjectContext = ...\nlet count = SomeManagedObject.count(in: context, with: predicate)\n```\n\n### Saving\n\nPersist the changes to the store by using the `perform` function provided on the context.\n\nThis function will apply the changes to a child context that is created from the initial context. And when these changes are successfully applies they will be merged into the initial context.\n\n```swift\ncontext.perform(changes: { localContext in\n  // Modify objects inside this closure. At the end of the closure the changes will be\n  // automatically persisted to the store.\n  // Make sure you do the changes on the given `localContext`.\n}, completion: {\n  // This completion closure will be called when `Duvel` finished writing to the store.\n})\n```\n\nSometimes you'll want update an existing `NSManagedObject`. If you want to do so and use the `perform` function, than you'll probably need to convert to object to an object from the `localContext`.\n\n```swift\nlet existingObject: SomeManagedObject = ...\ncontext.perform(changes: { localContext in\n  let localObject = existingObject.to(context: localContext)\n  localObject.name = \"Leroy\"\n}, completion: {\n  ...\n})\n```\n\n## Bucket List\n\nHere is an overview what is on our todo list.\n\n- [ ] Type safety for attribute creation.\n- [ ] Add notifications.\n\n## Author\n\nJelle Vandebeeck, jelle@fousa.be\n\n## License\n\nDuvel is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficapps%2Fios-duvel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ficapps%2Fios-duvel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficapps%2Fios-duvel/lists"}