{"id":13489204,"url":"https://github.com/michaelarmstrong/SuperRecord","last_synced_at":"2025-03-28T04:30:58.383Z","repository":{"id":22293636,"uuid":"25628374","full_name":"michaelarmstrong/SuperRecord","owner":"michaelarmstrong","description":"A small set of utilities to make working with CoreData and Swift a bit easier.","archived":false,"fork":false,"pushed_at":"2016-11-13T21:39:07.000Z","size":1194,"stargazers_count":366,"open_issues_count":7,"forks_count":27,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-03-05T04:20:00.967Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/michaelarmstrong.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":"2014-10-23T09:01:48.000Z","updated_at":"2024-04-23T14:35:54.000Z","dependencies_parsed_at":"2022-08-20T05:20:59.390Z","dependency_job_id":null,"html_url":"https://github.com/michaelarmstrong/SuperRecord","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelarmstrong%2FSuperRecord","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelarmstrong%2FSuperRecord/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelarmstrong%2FSuperRecord/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelarmstrong%2FSuperRecord/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michaelarmstrong","download_url":"https://codeload.github.com/michaelarmstrong/SuperRecord/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245970376,"owners_count":20702396,"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-07-31T19:00:19.958Z","updated_at":"2025-03-28T04:30:57.810Z","avatar_url":"https://github.com/michaelarmstrong.png","language":"Swift","funding_links":[],"categories":["Libs","Swift"],"sub_categories":["Data Management"],"readme":"SuperRecord  \n===================\n\n\n[![Build Status](https://travis-ci.org/michaelarmstrong/SuperRecord.svg)](https://travis-ci.org/michaelarmstrong/SuperRecord/)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n![CocoaPods](https://img.shields.io/cocoapods/v/SuperRecord.svg)\n\n\n===================\n\n\u003cb\u003e SUPPORTS SWIFT 2.0 from Version \u003e= 1.4 ** \u003c/b\u003e \u003cbr\u003e\n\u003cb\u003e SUPPORTS SWIFT 1.2 from Version \u003c= 1.3 \u003c/b\u003e \u003cbr\u003e\n\u003cb\u003e Both iOS and WatchOS \u003c/b\u003e\n \nA **Swift CoreData Framework** consisting of several **Extensions** and Helpers to bring some love and take the hassle out of common CoreData tasks.\n\n----------\nEach piece of functionality can be used independently and discreetly, so there is no need for a \"buy in\" to the whole project. For example, you could use your own `NSFetchedResultsController` or `NSManagedObjectContext` with any of the finders or even the `SuperFetchedResultsControllerDelegate`\n\nI'd like to make a big shout-out to MagicalRecord, which I think lay great foundations for these kind of projects. Although its had its ups and downs, it seems under heavy development. This Swift SuperRecord project was obviously heavily inspired by work done in MagicalRecord.\n\nFeatures\n-------------\n\nSuperRecord consists of several Extensions to add MagicalRecord/ActiveRecord style \"finders\" to your NSManagedObject subclasses, a **FetchResultsControllerDelegate** class to handle safe batch updates to both **UITableView** and **UICollectionView** and an experimental Boilerplate CoreData Stack Singleton.  \n\nThe project has been built over several versions of Swift so some choices may seem strange at first. \n\n### Adding SuperRecord to your project\n\n#### Method 1 (CocoaPods)\n\nTo integrate SuperRecord into your Xcode project using [CocoaPods](http://cocoapods.org/), specify it in your Podfile:\n\n\tuse_frameworks!\n\tpod 'SuperRecord'\n\nor for watch support use the subspec\n\n        pod 'SuperRecord/watch'\n\n\t\n- Build\t\n- Add import SuperRecord\n\n#### Method 2 (Carthage)\n\nTo integrate SuperRecord into your Xcode project using [Carthage](https://github.com/Carthage/Carthage), specify it in your Cartfile:\n\n\tgithub \"michaelarmstrong/SuperRecord\"\n\t\n\t\n#### Method 3 (Submodule)\n\n\tgit submodule add https://github.com/michaelarmstrong/SuperRecord.git SuperRecord\n\n- Drag the checked out submodule into Xcode\n- Click on your main application target\n- Open \"Build Phases\"\n- Add SuperRecord.framework under \"Target Dependencies\"\n\n#### Method 4 (Manually)\n\n\tgit clone https://github.com/michaelarmstrong/SuperRecord.git\n\t\nNow add the source files into your project directly.\n\n\n## Core Files\n\u003e - **NSManagedObjectExtension.swift** \n\u003e      This extension is responsible for most of the \"finder\" functionality and has operations such as `deleteAll()`, `findOrCreateWithAttribute()` `createEntity()` and allows you to specify your own `NSManagedObjectContext` or use the default one (running on the main thread).\n\u003e      \n\u003e - **NSFetchedResultsControllerExtension.swift**\n\u003e In constant development, this Extension allows the easy creation of `FetchedResultsControllers` for use with `UICollectionView` and `UITableView` that utilise the `SuperFetchedResultsControllerDelegate` for safe batch updates.\n\u003e\n\u003e - **SuperFetchedResultsControllerDelegate.swift** heavily inspired by past-projects i've worked on along with other popular open source projects. This handles **safe batch updates** to `UICollectionView` and `UITableView` across iOS 7 and iOS 8. It can be used on its own with your `NSFetchedResultsController` or alternatively, its automatically used by the `NSFetchedResultsControllerExtension` methods included in **SuperRecord**.\n\u003e\n\u003e - **SuperCoreDataStack.swift** a boilerplate experimental main thread CoreData stack. Can be used either as a sqlite store or in memory store. Simply by calling `SuperCoreDataStack.defaultStack()` for SQLite or `SuperCoreDataStack.inMemoryStack()` for an in memory store. Of course you have access to your context `.context` / `.saveContext()`\n\n## Usage\n\n#### \u003ci class=\"icon-file\"\u003e\u003c/i\u003e Create a new Entity\nAssuming you have an NSManagedObject of type \"Pokemon\" you could do the following\n\n\tlet pokemon = Pokemon.createNewEntity() as Pokemon\n\nPlease add `@objc(className)` above the class name of all your `NSManagedObject` subclasses (as shown in the demo project) for now. Better support will be coming in the future.\n\n#### \u003ci class=\"icon-folder-open\"\u003e\u003c/i\u003e Creating an NSFetchedResultsController\nThere are many factory methods for your convenience that **SuperRecord** adds to `NSFetchedResultsController` to make your life simpler, yet still powerful. As always, you don't have to use these with SuperRecord, however they are there for your convenience. Many of the SuperRecord factory methods will handle safe batch updates for you to your passed collectionView or tableView. No more song and dance.\n\n\tlazy var fetchedResultsController: NSFetchedResultsController = self.superFetchedResultsController()\n\t\n\tfunc superFetchedResultsController() -\u003e NSFetchedResultsController {\n\treturn NSFetchedResultsController.superFetchedResultsController(\"Pokemon\", tableView: tableView)\n\t}\n\nOr for some more advanced usage (collectionView with multiple sections and a predicate with automatic batch updates):\n\n    let sortDescriptors = [NSSortDescriptor(key: \"evolutionLevel\", ascending: false),NSSortDescriptor(key: \"level\", ascending: false)]\n    let predicate = NSPredicate(format: \"trainer = %@\", self.trainer)!\n    let tempFetchedResultsController = NSFetchedResultsController.superFetchedResultsController(\"Pokemon\", sectionNameKeyPath: \"evolutionLevel\", sortDescriptors: sortDescriptors, predicate: predicate, collectionView: self.collectionView, context: context)\t\n\n\nWith `Pokemon` being the entity name of your `NSManagedObject`.\n\n\n#### \u003ci class=\"icon-trash\"\u003e\u003c/i\u003e Delete Entities\n\nI'm planning on adding much more powerful functionality around Delete soon, such as deleteAllWithPredicate() or deleteEntity(), right now all that is available is\n\n\tPokemon.deleteAll()\n\n\n### Method Listing\nThis isn't an exhaustive list of all methods and classes, however it includes some of the most useful ones.\n\n#### NSManagedObjectExtension\n- `findAllWithPredicate(predicate: NSPredicate!, context: NSManagedObjectContext) -\u003e NSArray`\n- `findAllWithPredicate(predicate: NSPredicate!) -\u003e NSArray`\n- `deleteAll(context: NSManagedObjectContext) -\u003e Void`\n- `deleteAll() -\u003e Void`\n- `findAll(context: NSManagedObjectContext) -\u003e NSArray`\n- `findAll() -\u003e NSArray`\n- `findFirstOrCreateWithPredicate(predicate: NSPredicate!) -\u003e NSManagedObject`\n- `findFirstOrCreateWithPredicate(predicate: NSPredicate!, context: NSManagedObjectContext) -\u003e NSManagedObject`\n- `createNewEntity() -\u003e NSManagedObject`\n- `findFirstOrCreateWithAttribute(attribute: NSString!, value: NSString!, context: NSManagedObjectContext) -\u003e NSManagedObject`\n- `findFirstOrCreateWithAttribute(attribute: NSString!, value: NSString!) -\u003e NSManagedObject`\n\n\n#### NSFetchedResultsControllerExtension\n\n**`NSFetchedResultsControllers` created using the below methods will automatically handle safe batch updates to the passed `UITableView` or `UICollectionView`**\n\n- `superFetchedResultsController(entityName: NSString!, collectionView: UICollectionView) -\u003e NSFetchedResultsController`\n- `superFetchedResultsController(entityName: NSString!, tableView: UITableView) -\u003e NSFetchedResultsController`\n- `superFetchedResultsController(entityName: NSString!, sectionNameKeyPath: NSString?, sortDescriptors: NSArray?, predicate: NSPredicate?, collectionView: UICollectionView!, context: NSManagedObjectContext!) -\u003e NSFetchedResultsController`\n- `superFetchedResultsController(entityName: NSString!, sectionNameKeyPath: NSString?, sortDescriptors: NSArray?, predicate: NSPredicate?, tableView: UITableView!, context: NSManagedObjectContext!) -\u003e NSFetchedResultsController`\n\n**`NSFetchedResultsControllers` created using the below methods require you to use your own `NSFetchedResultsControllerDelegate` class**\n\n- `superFetchedResultsController(entityName: NSString!, sectionNameKeyPath: NSString?, sortedBy: NSString?, ascending: Bool, tableView: UITableView!, delegate: NSFetchedResultsControllerDelegate) -\u003e NSFetchedResultsController`\n- `superFetchedResultsController(entityName: NSString!, sectionNameKeyPath: NSString?, sortedBy: NSString?, ascending: Bool, collectionView: UICollectionView!, delegate: NSFetchedResultsControllerDelegate) -\u003e NSFetchedResultsController`\n- `superFetchedResultsController(entityName: NSString!, sectionNameKeyPath: NSString?, sortDescriptors: NSArray?, predicate: NSPredicate?, collectionView: UICollectionView!, delegate: NSFetchedResultsControllerDelegate) -\u003e NSFetchedResultsController`\n- `superFetchedResultsController(entityName: NSString!, sectionNameKeyPath: NSString?, sortDescriptors: NSArray?, predicate: NSPredicate?, tableView: UITableView!, delegate: NSFetchedResultsControllerDelegate) -\u003e NSFetchedResultsController`\n- `superFetchedResultsController(entityName: NSString!, sectionNameKeyPath: NSString?, sortDescriptors: NSArray?, predicate: NSPredicate?, collectionView: UICollectionView!, delegate: NSFetchedResultsControllerDelegate, context: NSManagedObjectContext!) -\u003e NSFetchedResultsController`\n- `superFetchedResultsController(entityName: NSString!, sectionNameKeyPath: NSString?, sortDescriptors: NSArray?, predicate: NSPredicate?, tableView: UITableView!, delegate: NSFetchedResultsControllerDelegate, context: NSManagedObjectContext!) -\u003e NSFetchedResultsController`\n\n##Developer Notes\n\nThis whole project is a work in progress, a learning exercise and has been released \"early\" so that it can be built and collaborated on with feedback from the community. I'm using it in a project I work on everyday, so hopefully it'll improve and gain more functionality, thread-safety and error handling over time.\n\nCurrently work is in progress to replace the SuperCoreDataStack with a much better, more flexible and cleaner implementation + a wiki is in progress. If you'd like to help out, please get in touch or open a PR.\n\n\n\n----------\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelarmstrong%2FSuperRecord","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichaelarmstrong%2FSuperRecord","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelarmstrong%2FSuperRecord/lists"}