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

Overview

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]
Comments
  • Develop

    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
    enhancement 
    opened by ABridoux 0
  • Release 0.6.1

    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
    opened by ABridoux 0
  • Release 0.4.0

    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.

    release 
    opened by ABridoux 0
  • DatabaseTestValue

    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.

    opened by ABridoux 0
  • Develop

    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.
    enhancement 
    opened by ABridoux 0
Releases(0.7.6)
Owner
Alexis Bridoux
Apple/Swift Developer at Karafun group
Alexis Bridoux
Arctanyn 0 Dec 24, 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.

null 0 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

Frederico Kückelhaus 0 May 10, 2022
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

Jason Fieldman 123 Oct 18, 2022
Simple IOS notes app written programmatically without storyboard using UIKit and CoreData

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

null 4 Dec 23, 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

Michael Armstrong 372 Jul 19, 2022
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.

Jason Fieldman 123 Oct 18, 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

Denis 16 Jun 2, 2022
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

Modo 2.1k Dec 29, 2022
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

Prisma Labs 89 Dec 29, 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

Manu Martinez 1 Oct 19, 2021
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

iMamad 1 Jun 1, 2022
Aplikasi iOS To Do List dengan Storyboard & Local CoreData (Database Xcode)

ToDoList Aplikasi iOS ToDoList adalah sebuah aplikasi CRUD sederhana berbasis iOS yang digunakan untuk membuat sebuah list item. Aplikasi ini dibuat m

DK 7 Aug 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

Daniyal Mohammed 3 Aug 29, 2022
QueryKit, a simple type-safe Core Data query language.

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

QueryKit 1.5k Dec 20, 2022
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

deeje cooley 123 Dec 31, 2022
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

null 782 Nov 6, 2022
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

deeje cooley 123 Dec 31, 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 Dependency managers Contact Swift 5.4: iOS 11+ / macOS 10.13+ / watchOS 4

John Estropia 3.7k Jan 9, 2023