{"id":20119177,"url":"https://github.com/abridoux/safefetching","last_synced_at":"2025-05-06T14:32:14.753Z","repository":{"id":38192988,"uuid":"420385030","full_name":"ABridoux/SafeFetching","owner":"ABridoux","description":"DSL to build predicates and requests for CoreData fetching","archived":false,"fork":false,"pushed_at":"2025-04-25T13:34:23.000Z","size":427,"stargazers_count":21,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-25T14:24:36.687Z","etag":null,"topics":["coredata","fetching","predicate","swift"],"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/ABridoux.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":"2021-10-23T10:47:27.000Z","updated_at":"2025-04-25T13:33:54.000Z","dependencies_parsed_at":"2023-01-19T05:15:54.663Z","dependency_job_id":null,"html_url":"https://github.com/ABridoux/SafeFetching","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ABridoux%2FSafeFetching","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ABridoux%2FSafeFetching/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ABridoux%2FSafeFetching/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ABridoux%2FSafeFetching/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ABridoux","download_url":"https://codeload.github.com/ABridoux/SafeFetching/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252703453,"owners_count":21790887,"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","fetching","predicate","swift"],"created_at":"2024-11-13T19:14:40.464Z","updated_at":"2025-05-06T14:32:14.317Z","avatar_url":"https://github.com/ABridoux.png","language":"Swift","readme":"# SafeFetching\n\nThis library offers a DSL (Domain Specific Language) to safely build predicates and requests to fetch a CoreData store. Also a wrapper around `NSFetchedResultsController` is offered to publish arrays of `NSManagedObject` to be used with a `NSDiffableDataSource`.\n\nThe documentation is built with docC. You can [read it online](https://abridoux.github.io/SafeFetching/documentation/safefetching/) or locally by running *Product* → *Build Documentation* or hitting **⇧⌃⌘D**.\n\n## Convenient and safe fetching\n\nFor any CoreData entity generated by Xcode, the only required step is to make it implement `Fetchable`.\n\n```swift\nfinal class RandomEntity: NSManagedObject {\n\n    @NSManaged var score = 0.0\n    @NSManaged var name: String? = \"\"\n}\n```\n\n```swift\nextension RandomEntity: Fetchable {}\n```\n\nThen it's possible to use the DSL to build a request. The last step can either get the built request as `NSFetchRequest\u003cRandomEntity\u003e` or execute the request in the provided context.\n\n```swift\nRandomEntity.request()\n    .all(after: 10)\n    .where(\\.score \u003e= 15 || \\.name != \"Joe\")\n    .sorted(by: .ascending(\\.score), .descending(\\.name))\n    .setting(\\.returnsDistinctResults, to: true)\n    .nsValue\n```\n\n```swift\nRandomEntity.request()\n    .all(after: 10)\n    .where(\\.score \u003e= 15 || \\.name != \"Joe\")\n    .sorted(by: .ascending(\\.score), .descending(\\.name))\n    .setting(\\.returnsDistinctResults, to: true)\n    .fetch(in: context) // returns [RandomEntity]\n```\n\nAdvanced `NSPredicate` operators are also available like `BEGINSWITH` (`hasPrefix`). To use one, specified a key path followed by `*`:\n\n```swift\nRandomEntity.request()\n    .all()\n    .where(\\.name * .hasPrefix(\"Do\"))\n    .nsValue\n```\n\nMore about that in the documentation.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabridoux%2Fsafefetching","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabridoux%2Fsafefetching","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabridoux%2Fsafefetching/lists"}