Swift Package for deduplicating entity protocol.

Overview

DeDuplicatingEntity

DeDuplicatingEntity is a protocol you can add to your Core Data model types to give them the functionality to deduplicate their instances based on a property of the model type you chose at deduplication time.

There is a sample project available here.

Instructions for use.

Get started by conforming your types to the DeDuplicatingEntity protocol. Once your model types conform to this protocol they get this functionality provided to them by the protocol extension.

All conforming types to be deduplicated must have a uuid: UUID? property declared in your model with a valid UUID saved to each instance. This is used to ensure multiple devices always choose to delete and keep the same copies of entities.

There is only one method you need to add to your model type.

func moveRelationships(to destination: MyNSManagedObjectSubclass)

Example conformance below:

extension MyNSManagedObjectSubclass: DeDuplicatingEntity {

    func moveRelationships(to destination: MyNSManagedObjectSubclass) {
        // Use this method to handle how your entities resolve relationships 
        // for deletion candidates to avoid orphan relationship objects. 
        // This method will be called on each deletion candidate 
        // just before deletion.

        // This is the place to move all existing relationships
        // to the destination instance, the one that will be kept, 
        // or handle them in other a ways that best suit your model.

        // You may leave an empty stub for this method on your entity 
        // if you don't have any relationship issues to resolve.
    }
}

Once your types conform to the protocol deduplicating them in your persistent store only requires one method call. static func deduplicateBy(property: String, in context: NSManagedObjectContext)

Call this method on the entity Type at an appropriate time and place in your application to deduplicate it's instances.

  • Parameters:

    • property: the property of the entities used to identify them as duplicates
    • context: a managed object context to work in. The context should be of NSManagedObjectContextConcurrencyType.privateQueueConcurrencyType so all work occurs on a background thread.
  • Important: The property parameter passed in must represent a String type property on your entity.

Example Usage:

// Called at an appropriate time and place in your app for deduplication
func deduplicate(in context: NSManagedObjectContext) {
    // The context should be of 
    // NSManagedObjectContextConcurrencyType.privateQueueConcurrencyType 
    // so all work occurs on a background thread.
    context.perform {
       MyNSManagedObjectSubclass.deduplicateBy(property: "name", in: context)
       // Deduplicate other types here....
    }
    // save context
    do {
       try context.save()
    } catch {
       let error = error as NSError
       print("Failed to save Context: \(error)")
    }
}
You might also like...
An NSPredicate DSL for iOS, OSX, tvOS, & watchOS. Inspired by SnapKit and lovingly written in Swift.
An NSPredicate DSL for iOS, OSX, tvOS, & watchOS. Inspired by SnapKit and lovingly written in Swift.

PrediKit A Swift NSPredicate DSL for iOS & OS X inspired by SnapKit, lovingly written in Swift, and created by that weird dude at KrakenDev. If you're

🎯 PredicateKit allows Swift developers to write expressive and type-safe predicates for CoreData using key-paths, comparisons and logical operators, literal values, and functions.
🎯 PredicateKit allows Swift developers to write expressive and type-safe predicates for CoreData using key-paths, comparisons and logical operators, literal values, and functions.

🎯 PredicateKit PredicateKit is an alternative to NSPredicate allowing you to write expressive and type-safe predicates for CoreData using key-paths,

This project server as a demo for anyone who wishes to learn Core Data in Swift.

CoreDataDemo This project server as a demo for anyone who wishes to learn Core Data in Swift. The purpose of this project is to help someone new to Co

Core functionality for Swift projects

Swift library with our shared code How to install .package(url: "https://github.com/ydataai/swift-core.git", from: "master"), About 👯‍♂️ With ❤️ from

Generates Swift NSManagedObject subclasses

MotoSwift. Managed Objects to Swift. Generates Swift NSManagedObject subclasses. Benefits Why is it better than Xcode generation? Xcode generates prop

TaskManager-CoreData - Swift IOS Application created primarily to familiarize with the CoreData framework and gain knowledge to work with it
SwiftFM is a Swift framework for the FileMaker Data API

SwiftFM SwiftFM is a Swift framework for the FileMaker Data API (Swift 5.5, iOS 15 required). It utilizes modern Swift features like async/await and i

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

A type-safe, fluent Swift library for working with Core Data
A type-safe, fluent Swift library for working with Core Data

Core Data Query Interface (CDQI) is a type-safe, fluent, intuitive library for working with Core Data in Swift. CDQI tremendously reduces the amount o

Releases(v1.0.1)
Owner
Vic Hudson
I like Swift and iOS development.
Vic Hudson
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
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
Swift client library to interact with Supabase Storage

storage-swift Swift Client library to interact with Supabase Storage.

Supabase 21 Dec 1, 2022
HitList is a Swift App shows the implementation of Core Data.

HitList HitList is a Swift App shows the implementation of Core Data. It is the demo app of Ray Wenderlich's tech blog. For details please reference G

Kushal Shingote 2 Dec 9, 2022
A type-safe, fluent Swift library for working with Core Data

Core Data Query Interface (CDQI) is a type-safe, fluent, intuitive library for working with Core Data in Swift. CDQI tremendously reduces the amount o

null 31 Oct 26, 2022
JSON to Core Data and back. Swift Core Data Sync.

Notice: Sync was supported from it's creation back in 2014 until March 2021 Moving forward I won't be able to support this project since I'm no longer

Nes 2.5k Dec 31, 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
100% Swift Simple Boilerplate Free Core Data Stack. NSPersistentContainer

DATAStack helps you to alleviate the Core Data boilerplate. Now you can go to your AppDelegate remove all the Core Data related code and replace it wi

Nes 216 Jan 3, 2023