Skip to content

Instantly share code, notes, and snippets.

View dnedrow's full-sized avatar

David Nedrow dnedrow

View GitHub Profile
@dnedrow
dnedrow / UIView+Shimmer.swift
Created February 27, 2020 00:27
Provides a shimmer animation for labels.
//
// UIView+Shimmer.swift
//
// Created by Romanov, Radu on 6/12/19.
//
import Foundation
extension UIView {
func startShimmerAnimation() {
@dnedrow
dnedrow / XCTestProtocol+IsRunning.swift
Last active March 9, 2020 13:36
Implement this protocol if you need to check whether the application is running in an XCTest context.
// Created by Nedrow, David E on 2018-11-03.
// Attribution 4.0 International (CC 4.0), see bottom.
import Foundation
/// Implement this protocol if you need to check whether the application is running in an XCTest context.
/// Default implementations are provided.
/// By their nature, these test–related queries can't themselves be exhaustively unit tested.
protocol XCTestProtocol {
/// Used to determine if the app is running in an XCTest context.
@dnedrow
dnedrow / UIColor+RGBAProtocol.swift
Last active March 3, 2020 13:25
Defines functions for transforming RGBA values.
// Created by Nedrow, David E on 2019-04-11.
// Attribution 4.0 International (CC 4.0), see bottom.
import Foundation
// MARK: - UIColor+RGBAProtocol.swift
/// Defines functions for transforming RGBA values.
public protocol RGBAProtocol {
/// Create a color from the given RGBA value.
@dnedrow
dnedrow / UIColor+ContrastColor.swift
Last active March 9, 2020 13:36
This protocol defines functions for determining contrasting colors and other color related values.
// Created by Nedrow, David E on 3/25/19.
// Attribution 4.0 International (CC 4.0), see bottom.
import UIKit
// MARK: - UIColor+ContrastColor.swift
/// This protocol defines functions for determining contrasting colors and other
/// color related values.
public protocol ContrastColorProtocol {
/// Calculates the luminance of the given color.
@dnedrow
dnedrow / UIColor+ARGBProtocol.swift
Last active March 9, 2020 13:39
Convenience functions for converting to and from ARGB.
// Created by Nedrow, David E on 3/25/19.
// Attribution 4.0 International (CC 4.0), see bottom.
import UIKit
// MARK: - UIColor+ARGBProtocol.swift
/// Definitions for ARGB related utilities.
public protocol ARGBProtocol {
/// Create a color from the given ARGB value.
///
@dnedrow
dnedrow / String+IntFromHex.swift
Last active March 9, 2020 13:40
This protocol defines functions related to hex string conversion.
// Created by Nedrow, David E on 3/25/19.
// This work is licensed under Attribution 4.0 International (CC 4.0)
import UIKit
// MARK: - String+IntFromHex.swift
/// This protocol defines functions related to hex string conversion.
public protocol HexStringProtocol {
/// Create an int from a given hex value string.
@dnedrow
dnedrow / PropertyStoring.swift
Last active March 9, 2020 13:41
"Stored properties" for Swift
// Created by Nedrow, David E on 2/21/18.
// This work is licensed under Attribution 4.0 International (CC 4.0)
import Foundation
/// Mechanism that provides something resembling stored properties for extensions.
///
/// Usage:
///
/// 1. Extend your class with the PropertyStoring protocol.
@dnedrow
dnedrow / String+Extensions.swift
Last active March 9, 2020 13:43
Provides various string utility functions.
// Created by David Nedrow on 4/9/19.
// This work is licensed under Attribution 4.0 International (CC 4.0)
public extension String {
/// returns the string from first `limit` number of characters. Appends `...` if string is truncated
func truncate(limit: Int) -> String {
guard self.count > limit else {
return self
}
@dnedrow
dnedrow / KeyedEncodingContainer+SCREAMING_SNAKE_CASE.swift
Last active March 9, 2020 13:46
This extension on KeyedEncodingContainer provides a handler for JSON codable and SCREAMING_SNAKE_CASE.
// Created by Nedrow, David E on 2019-06-28.
// This work is licensed under Attribution 4.0 International (CC 4.0)
import Foundation
/// This protocol provides access to the screaming snake case
/// value of a string.
public protocol ScreamingSnakeCaseRepresentable: Encodable {
/// The screaming snake case version.
var screamingSnakeCaseValue: String { get }
@dnedrow
dnedrow / Array+SafeIndexAccessible.swift
Created February 26, 2020 23:59
This extension to Array provides safe access to any index in an array, with a clean non-crashy result.
//
// Array_SafeAccess.swift
//
// Created by Zhao, Tyler on 6/26/19.
//
import Foundation
/// This protocol describes a function designed to return an optional
/// on a bad array access.