A fast, safe, flexible operation class for updating data stored in Core Data, written in Swift.

Overview

CoreDataOperation

Carthage compatible CocoaPods compatible CocoaPods compatible

CoreDataOperation is a fast, safe, flexible operation for updating your core data models. It supports the latest Swift 2.1 syntax, and does all its work in a background managed object context.

Installation

  • Using CocoaPods by adding pod CoreDataOperation to your Podfile
  • Using Carthage by adding github "Adlai-Holler/CoreDataOperation" to your Cartfile.

How to Use

let likeOperation = CoreDataOperation<Int>(targetContext: myContext, saveDepth: .ToPersistentStore) { context in
    guard let post = Post.withID(postID, inContext: context) else {
        throw Error.PostWasDeleted
    }
    if post.doILike {
        post.doILike = false
        post.likeCount -= 1
    } else {
        post.doILike = true
        post.likeCount += 1
    }
    post.updatedAt = NSDate()
    return post.likeCount
}
likeOperation.setCompletionBlockWithSuccess( { likeOperation, likeCount in
    // Switch to main queue to update UI
    dispatch_async(dispatch_get_main_queue()) {
        likeCountLabel.text = String(likeCount)
    }
}, failure: { likeOperation, error in
    dispatch_async(dispatch_get_main_queue()) {
        // Show an error.
    }
})
myOperationQueue.addOperation(likeOperation)

Features

  • Safe. All operations are confined to a private, background context, so if you get into a bad state, none of your working contexts will be affected.
  • Fully asynchronous. No threads are blocked, no two contexts are locked at the same time, and no context is locked for any longer than it absolutely must be.
  • Cancelable. The operation checks if it is canceled after each step.
  • Modern Swift syntax. Your operation block can throw an error, and it can return a value of any type which can be accessed after the operation is over.
  • Lightweight. The body block is disposed of after executing, and the target managed object context is not retained.
  • Tests! CoreDataOperation is tested like crazy.
You might also like...
SwiftLint - A tool to enforce Swift style and conventions, loosely based on Swift Style Guide.
SwiftLint - A tool to enforce Swift style and conventions, loosely based on Swift Style Guide.

SwiftLint - A tool to enforce Swift style and conventions, loosely based on Swift Style Guide.

Sweet-swift - Make Swift Sweet by Gracefully Introducing Syntactic Sugar, Helper Functions and Common Utilities

Sweet Swift Make Swift Sweet by Gracefully Introducing Syntactic Sugar, Helper F

Airbnb's Swift Style Guide.

Airbnb Swift Style Guide Goals Following this style guide should: Make it easier to read and begin understanding unfamiliar code. Make code easier to

LinkedIn's Official Swift Style Guide

Swift Style Guide Make sure to read Apple's API Design Guidelines. Specifics from these guidelines + additional remarks are mentioned below. This guid

 The Official raywenderlich.com Swift Style Guide.
The Official raywenderlich.com Swift Style Guide.

The Official raywenderlich.com Swift Style Guide. Updated for Swift 5 This style guide is different from others you may see, because the focus is cent

A self-taught project to learn Swift.
A self-taught project to learn Swift.

30 Days of Swift Hi Community I am Allen Wang, a product designer and currently learning Swift. This project was totally inspired by Sam Lu's 100 Days

Explanations and samples about the Swift programming language
Explanations and samples about the Swift programming language

About Swift Contents Explanations and samples about: Swift Programming Language Swift Standard Library Target audience Developers familiar with object

A collection useful tips for the Swift language
A collection useful tips for the Swift language

SwiftTips The following is a collection of tips I find to be useful when working with the Swift language. More content is available on my Twitter acco

Swift Featured Projects in brain Mapping
Swift Featured Projects in brain Mapping

Swift 开源精选   自 2014年 WWDC 发布 Swift 语言以来,本项目 一直致力于将主流 Swift 中文学习、开发资源汇集于此,并且尽力紧密地跟踪、甄选优秀 Swift 开源项目,以方便开发者快速获得并使用。考虑 Swift 已经正式发布超过四年半(更无力管理维护海量的 Swift

Comments
  • Correct the spelling of CocoaPods in README

    Correct the spelling of CocoaPods in README

    This pull requests corrects the spelling of CocoaPods 🤓 https://github.com/CocoaPods/shared_resources/tree/master/media

    opened by ReadmeCritic 2
Owner
Adlai Holler
Adlai Holler
This is a course project for CodePath Professional iOS Development class.

Parstagram - Part I This is an Instagram clone with a custom Parse backend that allows a user to post photos and view a global photos feed. Time spent

Mingkai Chen 0 Oct 13, 2021
CAEmitterBehavior: a undocumented class that dramatically increases the power of CAEmitterLayer

?? XSConfettiDemo ⚠️ Warn This demo uses the CAEmitterBehavior class. CAEmitterB

null 4 Nov 15, 2022
This to learn such as : Add Target , NSNotification Center Send/Get Data , Observer Override , resize Data By Byte , UIImagePicker Delegate , UIAlert Handle , Top ViewController , Get pickerController

Technicalisto How to Create UIButton Class to Pick Data Image Purpose Learn this topics With exact Task Add Target NSNotification Center Send/Get Data

Aya Baghdadi 1 Feb 20, 2022
Jared Watson 0 Jan 8, 2022
Movies app written in Swift 5 using the Custom API created on the Mocky website

Movie App shows you collections of TV streaming and other movies. Movie app writ

null 8 Dec 7, 2022
Model View Presenter Framework written in Swift.

BothamUI BothamUI is MVP (Model-View-Presenter) framework written in Swift. This project will help you setup all your presentation logic. BothamUI pro

Karumi 351 Sep 22, 2022
Exemplify a LazyVGrid in SwiftUI in a MVVM pattern with Mock Data and images in assets.

SwiftUI-LazyVGrid Exemplify a LazyVGrid in SwiftUI in a MVVM pattern with Mock Data and images in assets. Screenshots Samples IP & Credits All those b

Ethan Halprin 3 Aug 9, 2022
ClearScore - This application simulates a credit check on a user by making a call to an API and displaying the data

ClearScore Description This application simulates a credit check on a user by ma

Sashen Pillay 0 Jan 11, 2022
SampleProjectMVVM - Sample project using MVVM parsing data from Giphy.com

iOS Take Home Create an iOS app with two views, MainViewController and DetailVie

HG HrachGarabedian 0 Jan 27, 2022
⚛️ A Reactive Data-Binding and Dependency Injection Library for SwiftUI x Concurrency.

SwiftUI Atom Properties A Reactive Data-Binding and Dependency Injection Library for SwiftUI x Concurrency ?? API Reference Introduction Examples Gett

Ryo Aoyama 199 Dec 17, 2022