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
func isGermanTin(tin: String) -> Bool { | |
let endIndex = tin.index(tin.startIndex, offsetBy: 10) | |
let tinNumbers = tin[..<endIndex].compactMap { Int(String($0)) } | |
// First number can't be 0 | |
guard tinNumbers.first != 0 else { return false } | |
// There should be exactly 8 or 9 unique numbers and exactly one that has 2 occurrances | |
let occurances = tinNumbers.reduce(into: [:]) { $0[$1, default: 0] += 1 } | |
guard 8...9 ~= occurances.keys.count else { return false } | |
let occurranceCount = occurances.keys.count == 9 ? 2 : 3 | |
guard occurances.values.contains(where: { $0 == occurranceCount }) else { 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
import LocalAuthentication | |
extension LAContext { | |
/// BiometryType that works on iOS versions older than iOS 11. | |
var compatBiometryType: BiometryType { | |
var authError: NSError? | |
guard canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &authError), authError == nil else { return .none } | |
// On iOS 11 we can get the biometry type directly. | |
if #available(iOS 11.0, *) { | |
switch biometryType { |
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 ReactiveSwift | |
import ReactiveCocoa | |
import Kingfisher | |
extension Kingfisher: ReactiveExtensionsProvider { } | |
extension Reactive where Base == Kingfisher<UIImageView> { | |
var image: BindingTarget<URL?> { | |
return makeBindingTarget { | |
$0.setImage(with: $1) | |
} |
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 { | |
func string(withDelta deltaString: String) throws -> String { | |
var outString = String() | |
var indexPointer = self.startIndex | |
let inStringCount = self.utf16.count | |
try deltaString.components(separatedBy: "\t").forEach { string in | |
guard let firstChar = string.first else { return } | |
let param = string[string.index(after: string.startIndex)...] |
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 ReactiveSwift | |
import Result | |
extension Signal { | |
func injectError(_ error: Error, on signal: Signal<(), NoError>) -> Signal<Value, Error> { | |
return Signal { observer, lifetime in | |
lifetime += signal.observe { event in | |
if event.value != nil { | |
observer.send(error: error) |
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 Equatable { | |
func checkIfEqualTo<T: Equatable>(_ other: Self, byComparing paths: KeyPath<Self,T>...) -> Bool { | |
for keyPath in paths { | |
guard self[keyPath: keyPath] == other[keyPath: keyPath] else { | |
return false | |
} | |
} | |
return true | |
} | |
} |
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 UILayoutPriority { | |
/// Returns a UILayoutPriority that offsets an existing one by the specified value. | |
static func offset(_ prio: UILayoutPriority, by offset: Float) -> UILayoutPriority { | |
return UILayoutPriority(rawValue: prio.rawValue + offset) | |
} | |
} |
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 | |
/// A UILabel subclass that can hold attributes and apply them to text | |
@IBDesignable | |
final class Label: UILabel { | |
convenience init(attributes: [NSAttributedStringKey: Any]) { | |
self.init() | |
self.attributes = attributes | |
} | |
// MARK: Properties |
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 | |
func setupCodeFrom(uri: String) -> String { | |
let startIndex = uri.index(uri.startIndex, offsetBy: "X-HM://".count) | |
let endIndex = uri.index(uri.endIndex, offsetBy: -4) | |
var actualString = uri[startIndex..<endIndex] | |
let number = UInt(actualString, radix: 36)! | |
var code = String(format: "%08u", number & 0x7ffffff) |
NewerOlder