A feature-light wrapper around Core Data that simplifies common database operations.

Overview

header

Build Status Carthage Compatible CocoaPods Compatible GitHub license

Introduction

Core Data Dandy is a feature-light wrapper around Core Data that simplifies common database operations.

Feature summary

  • Initializes and maintains a Core Data stack.
  • Provides convenience methods for saves, inserts, fetches, and deletes.
  • Maps json into NSManagedObjects via a lightweight API.
  • Deserializes NSManagedObjects into json

Installation

Carthage

github "fuzz-productions/CoreDataDandy" ~> 0.6.1

CocoaPods

pod 'CoreDataDandy', '0.6.1'

Usage

All standard usage of Core Data Dandy should flow through CoreDataDandy's sharedDandy. More advanced users, however, may find its various components useful in isolation.

Bootstrapping

CoreDataDandy.wake("ModelName")

Saving and deleting

Save with or without a closure.

Dandy.save()
Dandy.save { error in
	// Respond to save completion.
}

Delete with or without a closure.

Dandy.delete(object)
Dandy.delete(object) {
	// Respond to deletion completion.
}

Destroy the contents of the database. Called, for example, to recover from a failure to perform a migration.

Dandy.tearDown()

Fetching

Fetch all objects of a given type.

Dandy.fetch(Gossip.self)

Fetch an object corresponding to an entity and primaryKey value.

Dandy.fetchUnique(Hat.self, identifiedBy: "bowler")

Fetch an array of objects filtered by a predicate.

Dandy.fetch(Gossip.self, filterBy: NSPredicate(format: "topic == %@", "John Keats"))

Insertions and updates

Insert object of a given type.

Dandy.insert(Gossip.self)

Insert or fetch a unique a object from a primary key.

Dandy.insertUnique(Slander.self, identifiedBy: "WILDE")

Upsert a unique object, or insert and update a non-unique object.

Dandy.upsert(Gossip.self, from: json)

Upsert an array of unique objects, or insert and update non-unique objects.

Dandy.batchUpsert(Gossip.self, from: json)

Mapping finalization

Objects requiring custom mapping finalization should adopt the MappingFinalizer protocol. The protocol has a single function, finalizeMapping(_:).

extension Conclusion: MappingFinalizer {
	func finalizeMapping(of json: [String : AnyObject]) {
		if var content = content {
			content += "_FINALIZED"
			self.content = content
		}
	}
}

Serialization

Serialize a single object.

Serializer.serialize(gossip)

Serialize an array of objects.

Serializer.serialize([byron, wilde, andre3000])

Serialize an object and its relationships.

Serializer.serialize(gossip, including: ["purveyor"])

Serialize an object and its nested relationships.

Serializer.serialize(gossip, including: ["purveyor.hats.material, purveyor.predecessor"])

xcdatamodel decorations

CoreDataDandy supports four xcdatamodel attributes. All decorations are declared and documented in DandyConstants.

@primaryKey

Add this decoration to the entity's userInfo to specify which property on the entity functions as its primaryKey.

@mapping

Add this decoration to a property to specify an alternate mapping for this property. For instance, if a property is named "abbreviatedState," but the json value for this property is found at the key "state," add @mapping : state to the abbreviatedState's userInfo.

@false

Use this decoration in conjunction with the @mapping keyword to disable mapping to the property. For instance, if your entity has an attribute named "secret" that you'd prefer to map yourself, add @mapping : @false to secret's userInfo.

@singleton

Add this decoration to an entity's userInfo if there should never be more than one instance of this entity in your database. This decoration may be useful for objects like Tokens and CurrentUsers, though it's primarily included to suggest the kind of decorations that may be added in the future.

Warnings

To receive console warnings in Swift projects, add the entry -D DEBUG in your project's build settings under Swift Compiler - Custom Flags.

You might also like...
A minimalistic, thread safe, non-boilerplate and super easy to use version of Active Record on Core Data.
A minimalistic, thread safe, non-boilerplate and super easy to use version of Active Record on Core Data.

Skopelos A minimalistic, thread-safe, non-boilerplate and super easy to use version of Active Record on Core Data. Simply all you need for doing Core

HitList is a Swift App shows the implementation of Core Data.
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

A synchronization framework for Core Data.

Core Data Ensembles Author: Drew McCormack Created: 29th September, 2013 Last Updated: 15th February, 2017 Ensembles 2 is now available for purchase a

Core Data code generation

mogenerator Visit the project's pretty homepage. Here's mogenerator's elevator pitch: mogenerator is a command-line tool that, given an .xcdatamodel f

Super Awesome Easy Fetching for Core Data!

MagicalRecord In software engineering, the active record pattern is a design pattern found in software that stores its data in relational databases. I

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

The Big Nerd Ranch Core Data Stack
The Big Nerd Ranch Core Data Stack

BNR Core Data Stack The BNR Core Data Stack is a small Swift framework that makes it both easier and safer to use Core Data. A better fetched results

100% Swift Simple Boilerplate Free Core Data Stack. NSPersistentContainer
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

Example repo of working with Core Data in a SwiftUI application

CoreData in SwiftUI This repository serves many purpose. But mostly so I can experiment with Core Data in SwiftUI, and also so I can use it show my ap

Owner
Fuzz Productions
Fuzz Productions
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
Core Data Generator (CDG for short) is a framework for generation (using Sourcery) of Core Data entities from plain structs/classes/enums.

Core Data Generator Introduction Features Supported platforms Installation CDG Setup RepositoryType ModelType DataStoreVersion MigrationPolicy Basic U

Lotusflare 18 Sep 19, 2022
Graph is a semantic database that is used to create data-driven applications.

Welcome to Graph Graph is a semantic database that is used to create data-driven applications. Download the latest sample. Features iCloud Support Mul

Cosmicmind 875 Oct 5, 2022
Super awesome Swift minion for Core Data (iOS, macOS, tvOS)

⚠️ Since this repository is going to be archived soon, I suggest migrating to NSPersistentContainer instead (available since iOS 10). For other conven

Marko Tadić 306 Sep 23, 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
JSQCoreDataKit - A swifter Core Data stack

JSQCoreDataKit A swifter Core Data stack About This library aims to do the following: Encode Core Data best practices, so you don't have to think "is

Jesse Squires 596 Dec 3, 2022
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

Just Eat 167 Mar 13, 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