Skip to content

Instantly share code, notes, and snippets.

public extension NSManagedObjectContext {
func addContextDidSaveNotificationObserver(center: NSNotificationCenter, handler: NSNotification -> ()) -> NSObjectProtocol {
return center.addObserverForName(NSManagedObjectContextDidSaveNotification, object: self, queue: nil) { notification in
handler(notification)
}
}
func performMergeChangesFromContextDidSaveNotification(notification: NSNotification) {
self.performBlock {
extension NSFetchedResultsController {
func registerForCommitsToContext(context: NSManagedObjectContext, notificationCenter: NSNotificationCenter? = nil) -> NSObjectProtocol? {
guard self.managedObjectContext != context else {
return nil
}
let center = notificationCenter ?? NSNotificationCenter.defaultCenter()
return center.addObserverForName(NSManagedObjectContextDidSaveNotification, object: context, queue: nil) { [weak self] notification in
guard let strongSelf = self else {
return
}
extension NSFetchedResultsController {
private func processChangesWithWillAccessValueForKey(notification: NSNotification) {
guard let _ = self.fetchRequest.predicate, _ = self.fetchRequest.entity else {
return
}
var matchingObjectIDs = self.insertedOrUpdatedObjectIDsMatchingFetchRequestInNotification(notification)
self.managedObjectContext.performBlock({
let registeredObjectIDs = self.managedObjectContext.registeredObjects.map{$0.objectID}
matchingObjectIDs.subtractInPlace(registeredObjectIDs)
for matchingObjectID in matchingObjectIDs {
@SixBe
SixBe / spin.swift
Last active July 13, 2016 08:24
Spinning a view with UIPropertyViewAnimator
let timing = UICubicTimingParameters(animationCurve: .easeInOut)
let animator = UIViewPropertyAnimator(duration: 6.0, timingParameters: timing)
// ball is a UIView
let rotationAnimation: ()->Void = {
ball.transform = ball.transform.rotate(CGFloat.pi)
}
for _ in 1...6 {
animator.addAnimations(rotationAnimation)
}
@SixBe
SixBe / Ball.swift
Created June 29, 2016 09:10
Class for a Ball view
public class Ball: UIView {
public init(radius: CGFloat) {
super.init(frame: CGRect(origin: .zero, size: CGSize(width: radius * 2, height: radius * 2)))
self.layer.cornerRadius = radius
self.backgroundColor = .red()
let indicator = UIView(frame: .zero)
self.addSubview(indicator)
import Foundation
@objc public protocol DataSourceProtocol: AnyObject {
@objc func runDataSourceRequest(_ dataSourceRequest: DataSourceRequest) -> AnyObject?
}
@objc public protocol DataSourceRequest {
var responseModel: AnyClass { get }