Skip to content

Instantly share code, notes, and snippets.

View AppsTitude's full-sized avatar

Louis Encontre AppsTitude

View GitHub Profile
@ole
ole / date-format-strings.swift
Last active October 8, 2020 04:25
Type-safe date format strings using string interpolation. Requires Swift 5.0.
// 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)
@lattner
lattner / TaskConcurrencyManifesto.md
Last active April 21, 2024 09:43
Swift Concurrency Manifesto
@myell0w
myell0w / KeyboardLayoutGuide.swift
Created July 19, 2017 14:53
A UILayoutGuide that follows the Keyboard on iOS
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
@chriseidhof
chriseidhof / sample.swift
Last active December 6, 2019 22:52
Observable References
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 {
@AppsTitude
AppsTitude / UICollection and NSFetchedResultsControllerDelegate integration.swift
Last active September 17, 2022 11:25
UICollectionView and NSFetchedResultsControllerDelegate integration in Swift
// 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)")
@kristopherjohnson
kristopherjohnson / locking.swift
Last active June 5, 2021 03:04
Simple synchronization functions for Swift, wrapping the Cocoa NSLocking classes
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 {}
@staltz
staltz / introrx.md
Last active April 24, 2024 19:47
The introduction to Reactive Programming you've been missing
@asmallteapot
asmallteapot / .gitattributes
Last active March 31, 2022 11:43
Diff Xcode localizable strings files in Git.
*.strings utf16 diff=localizablestrings
@sebreh
sebreh / NSManagedObjectContext+SRFetchAsync.h
Created May 20, 2013 20:07
Category for executing a Core Data fetch request in the background
#import <CoreData/CoreData.h>
@interface NSManagedObjectContext (SRFetchAsync)
- (void)sr_executeFetchRequest:(NSFetchRequest *)request completion:(void (^)(NSArray *objects, NSError *error))completion;
@end