Skip to content

Instantly share code, notes, and snippets.

View natanrolnik's full-sized avatar

Natan Rolnik natanrolnik

View GitHub Profile
@natanrolnik
natanrolnik / Dispatcher.swift
Created February 12, 2019 13:22
A small wrapper that manages multiple DispatchWorkItems
import Foundation
class Dispatcher {
private var items = [DispatcherIdentifier: DispatchWorkItem]()
private let queue: DispatchQueue
deinit {
cancelAllActions()
}
@natanrolnik
natanrolnik / CoreData+Extensions.swift
Last active May 14, 2019 12:50
Core Data Helpers
//The following code depends on this:
//https://gist.github.com/sisoje/f1444dff45618938ce81324a81316690#file-nspredicate-keypath-operators-swift
import CoreData
extension NSManagedObject {
static var entityName: String {
return entity().name!
}
}
//declare which keys in the JSON we are interested in
enum CodingKeys: String, CodingKey {
case status
case confirmedUsers
case position
case reason
}
//declare the possible values os the status key
private enum EventConfirmationStatus: String, Codable {
@natanrolnik
natanrolnik / Redundant Else
Created December 18, 2019 14:08
Examples of redundant else usage
------ ⭣ Redundant Else ⭣ ------
if someCondition {
return meh
} else {
let someValue = callSomeFunction()
return someValue
}
----------- ⭣ Fine ⭣ -----------