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 | |
// Extension adding class var random & computed property inverted to UIColor | |
extension UIColor { | |
static var random: UIColor { | |
UIColor(red: .random(in: 0...1), green: .random(in: 0...1), blue: .random(in: 0...1), alpha: .random(in: 0...1)) | |
} | |
static var randomSolid: UIColor { | |
UIColor(red: .random(in: 0...1), green: .random(in: 0...1), blue: .random(in: 0...1), alpha: 1.0) | |
} |
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 Foundation | |
extension String { | |
static func ~= (lhs: String, rhs: String) -> Bool { | |
guard let regex = try? NSRegularExpression(pattern: rhs) else { return false } | |
let range = NSRange(location: 0, length: lhs.utf16.count) | |
return regex.firstMatch(in: lhs, options: [], range: range) != nil | |
} | |
} |
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 | |
func * (lhs: CGSize, rhs: CGFloat) -> CGSize { | |
return CGSize(width: lhs.width * rhs, height: lhs.height * rhs) | |
} | |
func * (lhs: CGFloat, rhs: CGSize) -> CGSize { | |
return CGSize(width: lhs * rhs.width, height: lhs * rhs.height) | |
} |
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 | |
extension UIView { | |
var subviewsRecursive: [UIView] { | |
return subviews + subviews.flatMap { $0.subviewsRecursive } | |
} | |
} |
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 | |
extension UIView { | |
func addSubviews(_ views: UIView...) { | |
views.forEach { addSubview($0) } | |
} | |
} |
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 Foundation | |
class Person { | |
let name: String | |
private var teams = [Team]() | |
public var sortedTeams: [Team] { | |
return teams.sorted(by: { $0.rank < $1.rank }) | |
} | |
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 Foundation | |
class Debouncer { | |
/** | |
Create a new Debouncer instance with the provided time interval. | |
- parameter timeInterval: The time interval of the debounce window. | |
*/ | |
init(timeInterval: TimeInterval) { |
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
infix operator ???: NilCoalescingPrecedence | |
public func ??? <T>(optional: T?, defaultValue: @autoclosure () -> String) -> String { | |
return optional.map { String(describing: $0) } ?? defaultValue() | |
} |
OlderNewer