Domain Specific Language to safely build predicates and requests to fetch a CoreData store

Last update: May 8, 2022

SafeFetching

This 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.

The documentation is built with docC. To read it, run ProductBuild Documentation or hit ⇧⌃⌘D.

Note This repository is a split of CoreDataCandy to offer the fetching features alone

Convenient and safe fetching

For any CoreData entity generated by Xcode, the only required step is to make it implement Fetchable.

final class RandomEntity: NSManagedObject {

    @NSManaged var score = 0.0
    @NSManaged  var name: String? = ""
}
extension RandomEntity: Fetchable {}

Then it's possible to use the DSL to build a request. The last step can either get the built request as NSFetchRequest or execute the request in the provided context.

RandomEntity.request()
    .all(after: 10)
    .where(\.score >= 15 || \.name != "Joe")
    .sorted(by: .ascending(\.score), .descending(\.name))
    .setting(\.returnsDistinctResults, to: true)
    .nsValue
RandomEntity.request()
    .all(after: 10)
    .where(\.score >= 15 || \.name != "Joe")
    .sorted(by: .ascending(\.score), .descending(\.name))
    .setting(\.returnsDistinctResults, to: true)
    .fetch(in: context) // returns [RandomEntity]

Fetch update

When the entity type implements Fetchable, it's possible to call the static updatePublisher function to create a publisher backed by a NSFetchedResultsController that will emit arrays of the entity. This is especially useful when working with a NSDiffableDataSource.

    let request = RandomEntity.request()
        .all(after: 10)
        .where(\.score >= 15 || \.name != "Joe")
        .sorted(by: .ascending(\.score), .descending(\.name))
        .nsValue

    RandomEntity.updatePublisher(
        sortingBy: .ascending(\.name),
        for: request,
        in: context
    ) // emits [StubEntity]

GitHub

https://github.com/ABridoux/SafeFetching
Comments
  • 1. Develop

    Added

    • String comparison options (diacritic/case insensitive and normalized)
    • NSPredicate.safe(_:) to build a NSPredicate from SafeFetching predicate

    Fixed

    • Fixed option set comparison
    • CoreData imports
    • Wrong documentation symbols
    Reviewed by ABridoux at 2022-04-19 16:34
  • 2. Release 0.6.1

    Added

    • Online documentation at https://abridoux.github.io/SafeFetching/documentation/safefetching/

    Changed

    • Updated Readme to point to the new documentation

    Fixed

    • Dead link in the documentation
    Reviewed by ABridoux at 2022-03-19 16:59
  • 3. Release 0.4.0

    Added

    • DatabaseTestValue : protocol to allow values of several types that offers a string representation to be used as test value in a predicate.

    Changed

    Reworked the Predicate init to use DatabaseTestValue and be more flexible.

    Reviewed by ABridoux at 2022-02-03 09:50
  • 4. DatabaseTestValue

    Protocol to allow values of several types that offers a string representation to be used as test value in a predicate. Reworked the Predicate init to use that and be more flexible.

    Reviewed by ABridoux at 2022-02-03 09:48
  • 5. Develop

    • Moved extensions on RightValuePredicate in dedicated files
    • Fixed predicate on strings to work not only on optional ones
    • Added the protocol DatabaseValue to restrict the types that can be used to fetch.
    Reviewed by ABridoux at 2022-01-30 18:10
Feb 13, 2022
NYT Fetch Feeds Aviroc Test

NewYorkTimesNewsFeed iOS Project to load Build & Run Project Clone project github url provided Open project in Xcode by double clicking on AvriocTest.

Nov 25, 2021
iOS app built with UIKit and programatic auto-layouts to learn and apply knowledge. Offline storage using CoreData and Caching

PurpleImage Search Pixabay for images and save them offline to share and view To use: Clone the GitHub project, build and run in Xcode. The API is com

May 10, 2022
A Swift framework that wraps CoreData, hides context complexity, and helps facilitate best practices.
A Swift framework that wraps CoreData, hides context complexity, and helps facilitate best practices.

Cadmium is a Core Data framework for Swift that enforces best practices and raises exceptions for common Core Data pitfalls exactly where you make the

May 17, 2022
Simple IOS notes app written programmatically without storyboard using UIKit and CoreData
Simple IOS notes app written programmatically without storyboard using UIKit and CoreData

Notes Simple Notes app. Swift, UIKit, CoreData Description Simple IOS notes app

Mar 22, 2022
A small set of utilities to make working with CoreData and Swift a bit easier.

SuperRecord =================== SUPPORTS SWIFT 2.0 from Version >= 1.4 ** SUPPORTS SWIFT 1.2 from Version <= 1.3 Both iOS and WatchOS A Swift CoreData

May 14, 2022
A Swift framework that wraps CoreData, hides context complexity, and helps facilitate best practices.
A Swift framework that wraps CoreData, hides context complexity, and helps facilitate best practices.

Cadmium is a Core Data framework for Swift that enforces best practices and raises exceptions for common Core Data pitfalls exactly where you make them.

May 17, 2022
DataKernel is a minimalistic wrapper around CoreData stack to ease persistence operations.

DataKernel What is DataKernel? DataKernel is a minimalistic wrapper around CoreData stack to ease persistence operations. It is heavily inspired by Su

Jun 2, 2022
SugarRecord is a persistence wrapper designed to make working with persistence solutions like CoreData in a much easier way.
SugarRecord is a persistence wrapper designed to make working with persistence solutions like CoreData in a much easier way.

What is SugarRecord? SugarRecord is a persistence wrapper designed to make working with persistence solutions like CoreData in a much easier way. Than

Jun 16, 2022
CoreData based Swift ORM
CoreData based Swift ORM

Swift ORM Features Pure swift objects - no more subclasses of NSManagedObject Extensible attribute system - store any type in CoreData storage by impl

Jun 16, 2022
App agenda with CoreData

iOS Agenda App with CORE DATA Ejemplo de código para una aplicación de agenda, gestionando el modelo de datos con CoreData. Built using XCode 13.0 (Sw

Oct 19, 2021
CoreData + UI/Unit Tests + Pure Swift
CoreData + UI/Unit Tests + Pure Swift

What is it? ???? It's a Todo iOS Application with offline support by the use of Core Data which has been developed as a code challenge. It's written p

Jun 1, 2022
Quillow is an elegant book management app on the App Store that allows you to search, add and track the books you've consumed.

Quillow Quillow is an elegant book management app on the App Store that allows you to search, add and track the books you've consumed. Please use the

May 17, 2022
QueryKit, a simple type-safe Core Data query language.
QueryKit, a simple type-safe Core Data query language.

QueryKit QueryKit, a simple type-safe Core Data query language. Usage QuerySet<Person>(context, "Person")

Jun 16, 2022
Robust CloudKit synchronization: offline editing, relationships, shared and public databases, field-level deltas, and more.
Robust CloudKit synchronization: offline editing, relationships, shared and public databases, field-level deltas, and more.

CloudCore CloudCore is a framework that manages syncing between iCloud (CloudKit) and Core Data written on native Swift. Features Leveraging NSPersist

Jun 23, 2022
A powerful and elegant Core Data framework for Swift.
A powerful and elegant Core Data framework for Swift.

A powerful and elegant Core Data framework for Swift. Usage Beta version. New docs soon... Simple do that: let query = persistentContainer.viewContext

May 23, 2022
CloudCore is a framework that manages syncing between iCloud (CloudKit) and Core Data written on native Swift.
CloudCore is a framework that manages syncing between iCloud (CloudKit) and Core Data written on native Swift.

CloudCore CloudCore is a framework that manages syncing between iCloud (CloudKit) and Core Data written on native Swift. Features Leveraging NSPersist

Jun 23, 2022
Unleashing the real power of Core Data with the elegance and safety of Swift
 Unleashing the real power of Core Data with the elegance and safety of Swift

Unleashing the real power of Core Data with the elegance and safety of Swift Dependency managers Contact Swift 5.4: iOS 11+ / macOS 10.13+ / watchOS 4

Jun 25, 2022
JustPersist is the easiest and safest way to do persistence on iOS with Core Data support out of the box.
JustPersist is the easiest and safest way to do persistence on iOS with Core Data support out of the box.

JustPersist JustPersist is the easiest and safest way to do persistence on iOS with Core Data support out of the box. It also allows you to migrate to

Mar 13, 2022