Skip to content

Instantly share code, notes, and snippets.

View turk-jk's full-sized avatar
💭
had very long vacation, now time to work hard 💪🏾

yacob kazal turk-jk

💭
had very long vacation, now time to work hard 💪🏾
View GitHub Profile
@hlung
hlung / DynamicCodingKey.swift
Last active June 27, 2020 06:39
Decodes multiple layers of nested containers using a String array for key path. (It's actually cleaner to declare another struct for the nested data. But this is to show how this can be done.)
import Foundation
// Allows defining CodingKey from String
struct DynamicCodingKey: CodingKey {
var intValue: Int?
var stringValue: String
init?(intValue: Int) {
assertionFailure("Not implemented")
return nil
@TiagoBras
TiagoBras / DispatchQueue+Extensions.swift
Created April 18, 2019 11:07
DispatchQueue extension for situations where one needs to run an expensive operation in background and then use its result in the main thread
import Foundation
extension DispatchQueue {
func asyncConsumeInMainQueue<T>(
work: @escaping () throws -> T,
mainSuccess: @escaping (T) -> Void,
mainError: @escaping (Error) -> Void) {
async {
do {
let result = try work()
@Sorix
Sorix / FRCCollectionViewDataSource.swift
Created October 10, 2017 23:15
NSFetchedResultsControllerDelegate for UICollectionView
protocol FRCCollectionViewDelegate: class {
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
}
class FRCCollectionViewDataSource<FetchRequestResult: NSFetchRequestResult>: NSObject, UICollectionViewDataSource, NSFetchedResultsControllerDelegate {
let frc: NSFetchedResultsController<FetchRequestResult>
weak var collectionView: UICollectionView?
weak var delegate: FRCCollectionViewDelegate?