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
extension String { | |
func isContainedBy(set: CharacterSet) -> Bool { | |
let letters = self.components(separatedBy: set) | |
print(letters) | |
return self.count == letters.count | |
} | |
} |
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
extension UIEdgeInsets { | |
static func with(_ constant: CGFloat) -> UIEdgeInsets { | |
return UIEdgeInsets(top: constant, left: constant, bottom: constant, right: constant) | |
} | |
} | |
extension Comparable { | |
func clamp(min: Self, max: Self) -> Self { | |
if self < min { | |
return min |
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
extension UserDefaults { | |
@discardableResult | |
func serialize<V: Codable>(_ value: V, forKey key: String) -> Bool { | |
if let data = value.asPlistData { | |
self.set(data, forKey: key) | |
return self.synchronize() | |
} | |
return false |
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
// | |
// TextViewFormatter.swift | |
// TextViewFormatter | |
// | |
// Created by Daniel Esteban Cardona Rojas on 3/6/19. | |
// Copyright © 2019 Daniel Esteban Cardona Rojas. All rights reserved. | |
// | |
import UIKit | |
/* |
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
extension UITextView { | |
var currentWord: String? { | |
return currentWordRange.map({ String(text[$0]) }) | |
} | |
var currentWordRange: Range<String.Index>? { | |
let regex = try! NSRegularExpression(pattern: "\\S+$") | |
let textRange = NSRange(location: 0, length: selectedRange.location) | |
if let range = regex.firstMatch(in: text, range: textRange)?.range { | |
return Range(range, in: text) |
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
extension Comparable { | |
func clamped(min: Self, max: Self) -> Self { | |
if self < min { | |
return min | |
} | |
if self > max { | |
return max | |
} | |
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 UIKit | |
import Foundation | |
protocol Coordinator: class { | |
typealias ExitHandler = (Coordinator) -> Void | |
var childCoordinators: [Coordinator] { get set } | |
var navigationController: UINavigationController { get set } | |
var initialViewController: UIViewController? { get } | |
func willNavigate(from: UIViewController, to: UIViewController) | |
func start() |
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
/* | |
It is encouraged to use the same class name for the controller story board identifier, | |
but this protocol is flexible to allow defining the story from where to instantiate the | |
controller as well its identifier. | |
You can choose to keep the convention while just changing the story board where the controller | |
is located. | |
e.g: | |
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
@IBDesignable | |
class RevealView: UIView { | |
var contentHeight: CGFloat = 300 | |
@IBInspectable var title: String = "" { | |
didSet { | |
titleLabel.text = title | |
} | |
} |
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
struct Cached <V, C> { | |
typealias Computation = (V) -> C | |
private var computation: (V) -> C | |
private var cachedResult: C? | |
var value: V { | |
willSet { | |
cachedResult = nil | |
} | |
} |