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 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) |
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
// 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 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 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
[ | |
{ | |
"themeName": "base", | |
"colors": [ | |
{ | |
"name": "colorPrimary", | |
"hex": "fafafa" | |
}, | |
{ | |
"name": "colorOnPrimary", |
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
// Module: Domain | |
struct KitchenUseCase { | |
// Obtains stuff already stored in some place inside the restaurant | |
// For example: fetching it from CoreData, KeychainManager, UserDefaults and so on. | |
private let localDataSource: KitchenLocalRepository | |
// Obtains stuff needed from outside of our restaurant. | |
// For example: doing API calls to a NetworkManager. |
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
// Module: Domain | |
protocol Cookable { | |
func cook() | |
} | |
protocol Recipe: Cookable { | |
// Recipe definition | |
} |
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
public protocol KitchenLocalRepository { | |
public func getIngredients(_ recipe: Recipe) -> [Ingredient]? | |
} | |
public protocol KitchenRemoteRepository { | |
public func getIngredients(_ recipe: Recipe, completion: ([Ingredient]?) -> Void)) | |
} | |
public protocol CookerProtocol { | |
public func cook(_ recipe: Recipe) |
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
// Module: Data | |
import Domain | |
public struct: ItalianCooker: CookerProtocol { | |
func cook(_ recipe: Recipe) { | |
switch recipe { | |
case recipe is SpaghettiCarbonara: | |
cookSpaghettiCarbonara(recipe) |
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
// Module: Data | |
import Domain | |
public struct KitchenLocalDataSource: KitchenLocalRepository { | |
public func getIngredients(_ recipe: Recipe) -> [Ingredient]? { | |
// do something to fetch the ingredients needed from some local store: UserDefaults, CoreData, Memory Cache, KeychainManager etc | |
} | |
} |
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
// Module: CleanArchitectureRestaurant | |
import Domain | |
import Data | |
import Presentation | |
final class DinningHallDIContainer { | |
func makeKitchenUseCase() -> KitchenUseCase { | |
let cooker = ItalianCooker() |
OlderNewer