Author: Chris Lattner
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
// 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) |
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 | |
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 |
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 | |
// 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 { |
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
// 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)") |
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 | |
/// 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 {} |
(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.
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
*.strings utf16 diff=localizablestrings |
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 <CoreData/CoreData.h> | |
@interface NSManagedObjectContext (SRFetchAsync) | |
- (void)sr_executeFetchRequest:(NSFetchRequest *)request completion:(void (^)(NSArray *objects, NSError *error))completion; | |
@end |