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 | |
typealias ConnectionDrawing = Void -> Void | |
class LineGraphView: UIView { | |
var data = [Double]() | |
var offset: CGFloat = 0.0 | |
var shownRange = 0 ..< 0 | |
var maximumValueShown: Double = 0.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
import UIKit | |
extension UIView { | |
/// Checks the constraints of this view's superview, as well as all of it's subviews, for the constraint with the identifier passed. | |
func constraint(withIdentifier identifier: String) -> NSLayoutConstraint? { | |
if let constraint = superview?.constraintFiltered(identifier) { | |
return constraint | |
} else if let constraint = constraintFiltered(identifier) { | |
return constraint |
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
/// Used to identify the intended format of a string when using the `attributedTextFromArray:` func of a UILabel extension. | |
enum FontType { | |
case system, bold, italic, underlined | |
} | |
extension UILabel { | |
/** | |
Assigns attributed text to the label by iterating through an array of strings with associated FontTypes. | |
Example use: |
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 | |
/** | |
In the xib IB, make the used custom view class (subclass of NibView) | |
the File’s Owner and connect the view outlet to the xib view. | |
*/ | |
class NibView: UIView { | |
@IBOutlet weak private var view: UIView! | |
var nibName: String { |
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 | |
// NOTE: percentageThreshold is shared across all instances of SwipeControl | |
private var percentageThreshold: Int = 75 | |
private enum Direction { | |
case left, right, none | |
} |
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 validateArray<T>(_ array: [T?]) -> [T] { | |
var validElements: [T] = [] | |
for case let element? in array { | |
validElements.append(element) | |
} | |
return validElements | |
} |
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 | |
extension UIAlertAction { | |
convenience init(title: String, handler: ((UIAlertAction?) -> Void)? = nil) { | |
self.init(title: title, style: .default, handler: handler) | |
} | |
} | |
/// - Tag: AlertHelper | |
struct AlertHelper { |
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 | |
// MARK: - ImageLoader Protocol | |
public typealias ImageLoaderHandler = (UIImage?, Error?) -> Void | |
public protocol ImageLoader { | |
func updateImage(fromURLString urlString: String?, placeholderImage: UIImage?, completionHandler: @escaping ImageLoaderHandler) | |
func imageFromCache(_ urlString: String?) -> UIImage? | |
} |
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 | |
/** | |
The adopting UIView is the File Ower of a nib by the same name. All IBOutlets are wired through the File Owner (not the content view itself) and the content view is also wired to the IBOutlet `view`. | |
NOTE - `loadFromNib:` must be called within a convenience initializer. | |
Keep in mind that any UIView instance method that you would normally use `self` should be called `view` instead. | |
*/ | |
protocol NibViewType: UIAppearance { |
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 | |
struct StoryboardHelper { | |
/// Assumes that the storyboard identifier for the View Controller class provided matches its name and that it has been added to the `storyboardNameForViewController` switch statement. | |
static func new<T>() -> T? { | |
let nibName = String(describing: T.self) | |
let storyboardName = storyboardNameForViewController(named: nibName) | |
return getViewController(named: nibName, fromStoryboardNamed: storyboardName) as? T | |
} |
OlderNewer