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
------ ⭣ Redundant Else ⭣ ------ | |
if someCondition { | |
return meh | |
} else { | |
let someValue = callSomeFunction() | |
return someValue | |
} | |
----------- ⭣ Fine ⭣ ----------- |
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
//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 { |
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
//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! | |
} | |
} |
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 | |
class Dispatcher { | |
private var items = [DispatcherIdentifier: DispatchWorkItem]() | |
private let queue: DispatchQueue | |
deinit { | |
cancelAllActions() | |
} |
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
var micHintWorkItem: DispatchWorkItem? | |
func recordVoiceMessage() { | |
micHintWorkItem?.cancel() | |
} | |
//in your viewDidAppear method, create and schedule the work item: | |
micHintWorkItem = DispatchWorkItem { [weak self] in | |
self?.micButton.jump() | |
} |
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
//keep a variable to know if the user tapped the button: | |
var micButtonTapped = false | |
func recordVoiceMessage() { | |
//if the user tapped/held the mic button, set the variable to true | |
micButtonTapped = true | |
} | |
//in your viewDidAppear method, schedule it: | |
DispatchQueue.main.asyncAfter(.now() + 3) { [weak self] in |
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
//in your viewDidAppear method, schedule it: | |
DispatchQueue.main.asyncAfter(.now() + 3) { [weak self] in | |
self?.micButton.jump() | |
} |
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
class NotificationThrottler { | |
let notificationCenter: NotificationCenter | |
let timeInterval: TimeInterval | |
let handler: () -> Void | |
private var workItem: DispatchWorkItem? | |
deinit { | |
notificationCenter.removeObserver(self) | |
} |
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
PlaygroundPage.current.needsIndefiniteExecution = true | |
typealias DispatcherIdentifier = String | |
extension DispatchQueue { | |
static var associatedValueKey = 0 | |
func schedule(after timeInterval: TimeInterval, | |
with identifier: DispatcherIdentifier, | |
action: @escaping () -> Void) { |
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 PlaygroundSupport | |
typealias DispatcherIdentifier = String | |
class Dispatcher { | |
private var items = [DispatcherIdentifier: DispatchWorkItem]() | |
private let queue: DispatchQueue |
NewerOlder