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 NSMutableAttributedString { | |
| func replacingOccurrences(of item: String, with replacement: NSAttributedString) { | |
| guard let range: Range<String.Index> = self.string.range(of: item) else { | |
| return | |
| } | |
| let nsrange = NSRange(range, in: self.string) | |
| self.replaceCharacters(in: nsrange, with: replacement) | |
| } | |
| } |
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 interspersing(_ element: Element) -> Array { | |
| var newArray: [Element] = [] | |
| for (index, item) in self.enumerated() { | |
| newArray.append(item) | |
| if index < self.count - 1 { | |
| newArray.append(element) | |
| } | |
| } | |
| return newArray |
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 UIStackView { | |
| func insertSeparator(_ createSeparator: (() -> UIView)) { | |
| let subviews = self.arrangedSubviews | |
| for v in subviews { | |
| self.removeArrangedSubview(v) | |
| } | |
| for v in subviews { | |
| self.addArrangedSubview(v) |
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
| // | |
| // ProfileInputField.swift | |
| // CustomViews | |
| // | |
| // Created by Daniel Esteban Cardona Rojas on 9/14/18. | |
| // Copyright © 2018 Daniel Esteban Cardona Rojas. All rights reserved. | |
| // | |
| import UIKit |
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 flattened<T>() -> [T] where Element == [T] { | |
| return self.flatMap({ $0 }) | |
| } | |
| func all(_ pred: (Element) -> Bool) -> Bool { | |
| return self.reduce(true, { acc, v in acc && pred(v) }) | |
| } | |
| func any(_ pred: (Element) -> Bool) -> Bool { |
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 String { | |
| func isContainedBy(set: CharacterSet) -> Bool { | |
| let letters = self.components(separatedBy: set) | |
| print(letters) | |
| return self.count == letters.count | |
| } | |
| func filtered(by set: CharacterSet) -> String { | |
| let chars = self.unicodeScalars.filter({ set.contains($0)}) | |
| let unicode = UnicodeScalarView(chars) |
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 String { | |
| func isContainedBy(set: CharacterSet) -> Bool { | |
| let letters = self.components(separatedBy: set) | |
| print(letters) | |
| return self.count == letters.count | |
| } | |
| } |
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 UIScrollView { | |
| func scrollSubViewToTop(_ subview: UIView, offset: CGFloat, animated: Bool) { | |
| let point = convert(subview.frame.origin, from: subview.superview ?? subview) | |
| setContentOffset(CGPoint(x: 0, y: point.y - offset), animated: animated) | |
| } | |
| func viewPortOffset(of subview: UIView) -> CGFloat { | |
| let point = convert(subview.frame.origin, from: subview.superview ?? subview) | |
| return point.y - contentOffset.y | |
| } |
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 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 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 PromiseKit | |
| extension APIClient { | |
| func request<Response, T>(_ requestConvertible: T, | |
| additionalHeaders headers: [String: String]? = nil, | |
| additionalQuery queryParameters: [String: String]? = nil, | |
| baseUrl: URL? = nil) -> Promise<T.Result> | |
| where T: URLResponseCapable, T: URLRequestConvertible, T.Result == Response { | |
| return Promise { seal in | |
| self.request(requestConvertible, additionalHeaders: headers, additionalQuery: queryParameters, success: { response in |