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 Reactive where Base == UIScreen { | |
@available(iOS 13.0, *) | |
func userInterfaceStyle() -> Observable<UIUserInterfaceStyle> { | |
let currentUserInterfaceStyle = UITraitCollection.current.userInterfaceStyle | |
let initial = Observable.just(currentUserInterfaceStyle) | |
let selector = #selector(UIScreen.traitCollectionDidChange(_:)) | |
let following = self.base | |
.rx | |
.methodInvoked(selector) | |
.flatMap { (args) -> Observable<UIUserInterfaceStyle> in |
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
// Only contents of UIKit can use DynamicColors. So if you need the dynamic color behavior | |
// on CALayer, CGColor etc you need to use one of these 3 options: | |
// Option 1 | |
let resolvedColor = UIColor.label.resolvedColor(with: traitCollection) | |
layer.borderColor = resolvedColor.cgColor | |
// Option 2 | |
traitCollection.perfomAsCurrent { | |
layer.borderColor = UIColor.label.cgColor |
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 isNifValid(nif: String) -> Bool { | |
guard nif.count == 9, let nifPrefix = Int(nif.prefix(1)) else { return false } | |
if [1, 2, 5, 6, 9].contains(nifPrefix) { | |
var checkDigit = nifPrefix * 9 | |
for index in 2...nif.count - 1 { | |
let indexBound = nif.index(nif.startIndex, offsetBy: index - 1) | |
checkDigit += (Int(String(nif[indexBound])) ?? 0) * (10 - index) |
NewerOlder