This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
@objc public protocol DataSourceProtocol: AnyObject { | |
@objc func runDataSourceRequest(_ dataSourceRequest: DataSourceRequest) -> AnyObject? | |
} | |
@objc public protocol DataSourceRequest { | |
var responseModel: AnyClass { get } |