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
| infix operator ??= | |
| func ??=<T>(lhs: inout T, rhs: T?) { | |
| guard let rhs = rhs else { | |
| return | |
| } | |
| lhs = rhs | |
| } | |
| // This collapses and obviates redundant-looking use of the nil coalescing operator | |
| // so that given this: |
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
| Pod::Spec.new do |s| | |
| s.name = '{YOUR POD NAME}' | |
| s.version = '0.0.1' | |
| s.summary = '{HIGH LEVEL, ONE-SENTENCE SUMMARY}' | |
| s.description = <<-DESC | |
| {LONG-FORM DESCRIPTION OF YOUR COCOAPOD} | |
| Tags: {A COMMA-SEPARATED LIST OF SEARCHABLE TAGS} | |
| DESC | |
| # I recommend writing a git hook that scrapes this from your README.md file. |
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 | |
| import UIKit | |
| class ToggleableStackView: UIStackView { | |
| enum Cohort { | |
| case primary | |
| case secondary | |
| var next: Cohort { | |
| switch self { | |
| case .primary: |
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
| extension UIImageView | |
| func setImage(withColor color: UIColor) { | |
| image = UIImage.withColor(color, size: bounds.size) | |
| } | |
| } | |
| extension UIImage { | |
| static func withColor(_ color: UIColor, size: CGSize) -> UIImage { | |
| let rect = CGRect(origin: CGPoint.zero, size: size) | |
| UIGraphicsBeginImageContextWithOptions(size, false, 0) |
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
| func almostIncreasingSequence(sequence: [Int]) -> Bool { | |
| let count = sequence.count | |
| if count < 3 { | |
| return true | |
| } | |
| if sequence.sorted() == sequence { | |
| return isStrictlyAscending(array: sequence) | |
| } | |
| var mutableSequence = sequence |
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
| extension Array where Element: Hashable { | |
| func asSet() -> Set<Element> { | |
| return Set(self) | |
| } | |
| } | |
| extension Set { | |
| func asArray() -> [Element] { | |
| return Array(self) | |
| } |
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
| extension Array { | |
| func mapToDictionary<Key:Hashable,Value>(mapBlock: (Element)->(Key,Value)) -> [Key:Value] { | |
| var dict = [Key:Value]() | |
| self.forEach { (element) in | |
| let kvTuple: (Key,Value) = mapBlock(element) | |
| dict[kvTuple.0] = kvTuple.1 | |
| } | |
| return dict | |
| } | |
| } |
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
| extension Optional where Wrapped: Collection { | |
| /* | |
| NOTE: Since this extends Optional rather than the possible collection, | |
| you don't use the "?" when calling it `isEmptyOrNil()` | |
| Example: | |
| var myString: String? = "" | |
| myString.isEmptyOrNil // Evaluates to true. | |
| myString = nil | |
| myString.isEmptyOrNil // Also evaluates to true. | |
| myString?.isEmptyOrNil // Will not compile. |
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 BlockRefreshControl: UIRefreshControl { | |
| private let block: ()->() | |
| init(block: @escaping ()->()) { | |
| self.block = block | |
| super.init() | |
| addTarget(self, action: #selector(BlockRefreshControl.peformBlock), for: .valueChanged) | |
| } |
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
| extension UIStoryboard { | |
| static func instantiateInitialVC<T: UIViewController>() -> T { | |
| let className = String(describing: T.self) | |
| return instantiateInitialVC(storyboardName: className) | |
| } | |
| static func instantiateInitialVC<T: UIViewController>(storyboardName: String) -> T { | |
| let className = String(describing: T.self) | |
| let storyboard = UIStoryboard(name: storyboardName, bundle: nil) | |
| guard let instance = storyboard.instantiateInitialViewController() as? T else { |