This file contains hidden or 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 UIKit | |
| class ActionSheetAnimationController: NSObject, UIViewControllerAnimatedTransitioning { | |
| enum Direction { | |
| case enter, exit | |
| } | |
| let direction: Direction | |
| let duration: TimeInterval | |
This file contains hidden or 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 | |
| extension Array { | |
| func groupedBy<T: Hashable>(key: (Element) -> T, sort: ((Element, Element) -> Bool)? = nil) -> [T: [Element]] { | |
| var groups = [T: [Element]]() | |
| mainLoop: for element in self { | |
| let elementKey = key(element) | |
| if groups[elementKey] == nil { |
This file contains hidden or 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 | |
| extension DispatchQueue { | |
| func asyncConsumeInMainQueue<T>( | |
| work: @escaping () throws -> T, | |
| mainSuccess: @escaping (T) -> Void, | |
| mainError: @escaping (Error) -> Void) { | |
| async { | |
| do { | |
| let result = try work() |
This file contains hidden or 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 | |
| enum DateFormat: String { | |
| /// Format: yyyy-MM-dd | |
| case yyyyMMdd = "yyyy-MM-dd" | |
| /// Format: yyyy-MM-DD HH:mm | |
| case yyyyMMddHHmm = "yyyy-MM-DD HH:mm" | |
| /// Format: dd/MM/yyyy HH:mm:ss |
This file contains hidden or 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 Observable<T: Equatable> { | |
| typealias HandlerID = UUID | |
| struct Observer { | |
| typealias Handler = (T) -> () | |
| let id: HandlerID | |
| let handler: Handler |
This file contains hidden or 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
| // Swift 4 | |
| extension UIImage { | |
| func maskWith(color: UIColor) -> UIImage { | |
| UIGraphicsBeginImageContextWithOptions(size, false, 0) | |
| let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height) | |
| color.setFill() | |
| draw(in: rect) |