Skip to content

Instantly share code, notes, and snippets.

@chrsp
Last active July 18, 2022 15:24
Show Gist options
  • Save chrsp/1ce93ca1a1b2e25dc9a9022627fca018 to your computer and use it in GitHub Desktop.
Save chrsp/1ce93ca1a1b2e25dc9a9022627fca018 to your computer and use it in GitHub Desktop.
// 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
}
}
public struct KitchenRemoteDataSource: KitchenRemoteRepository {
public func getIngredients(_ recipe: Recipe, completion: ([Ingredient]?) -> Void)) {
// do something to fetch the ingredients needed from some remote store, usually calling your NetworkManager here
}
}
@harshadeepak11
Copy link

Hi @chrsp , May i know what is import Domain Here?

@harshadeepak11
Copy link

harshadeepak11 commented Jul 18, 2022

In Domain Layer we have, Struct KitchenUseCase, KitchenProtocols and SpaghettiCarbonara files. So, what should i import for the Domain?
May i know where to call the below function from
public func prepareRecipe(_ recipe: Recipe) { }
Can i please have your email id, so that. can send the code i wrote based on your explanation.

@chrsp
Copy link
Author

chrsp commented Jul 18, 2022

Hi @harshadeepak11 . The Domain would contain normally the Models (DTOs) and the use cases of your system. This import works to illustrate that the Recipeand Ingredient comes from a module from outside. You could also create a dependency injection container to avoid the import, normally that would be the preferred approach in a real-world scenario.

@harshadeepak11
Copy link

Thanks a lot for quick reply sir.
I am still a bit confused in Importing, It would be really helpful for me if you could please send me the finished project possibly.
Here I am - harshadeepak11@yahoo.co.in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment