(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| #import <CoreData/CoreData.h> | |
| @interface NSManagedObjectContext (SRFetchAsync) | |
| - (void)sr_executeFetchRequest:(NSFetchRequest *)request completion:(void (^)(NSArray *objects, NSError *error))completion; | |
| @end |
| *.strings utf16 diff=localizablestrings |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| import Foundation | |
| /// Protocol for NSLocking objects that also provide tryLock() | |
| public protocol TryLockable: NSLocking { | |
| func tryLock() -> Bool | |
| } | |
| // These Cocoa classes have tryLock() | |
| extension NSLock: TryLockable {} | |
| extension NSRecursiveLock: TryLockable {} |
| // I just implemented that with Swift. So I would like to share my implementation. | |
| // First initialise an array of NSBlockOperations: | |
| var blockOperations: [NSBlockOperation] = [] | |
| // In the did change object method: | |
| func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) { | |
| if type == NSFetchedResultsChangeType.Insert { | |
| println("Insert Object: \(newIndexPath)") |
| import Foundation | |
| // A lens is a getter and a setter combined | |
| struct Lens<Whole, Part> { | |
| let get: (Whole) -> Part | |
| let set: (inout Whole, Part) -> () | |
| } | |
| // We can create a lens from a key path | |
| extension Lens { |
| import Foundation | |
| import UIKit | |
| /// Used to create a layout guide that pins to the top of the keyboard | |
| final class KeyboardLayoutGuide { | |
| private let notificationCenter: NotificationCenter | |
| private let bottomConstraint: NSLayoutConstraint |
Author: Chris Lattner
| // Type-safe date format strings using string interpolation | |
| // Requires Swift 5.0. | |
| import Foundation | |
| enum DateFormatComponent { | |
| case era(AlphaStyle) | |
| case year(MinimumDigits) | |
| case yearForWeekOfYear(MinimumDigits) | |
| case quarter(AlphaNumericStyle) |