Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
39 lines (30 sloc) 868 Bytes
//: Playground by Ihor Malovanyi & justDev team. Enjoy!
import UIKit
struct Product {
var name: String
var price : Double
}
protocol ProductsRepository {
func fetchProducts() -> [Product]
}
struct ProductsRepositoryImplementation : ProductsRepository {
func fetchProducts() -> [Product] {
return [Product(name: "Adidas Sneakers", price: 2030.0), Product(name: "Nike Sneakers", price: 1000.0)]
}
}
protocol ProductsRepositoryInjectable {
var products : ProductsRepository {get}
}
extension ProductsRepositoryInjectable {
var products : ProductsRepository {
return ProductsRepositoryImplementation()
}
}
struct ProductViewModel: ProductsRepositoryInjectable {
init() {
self.products.fetchProducts().forEach {
print("This \($0.name) costs $\($0.price)")
}
}
}
ProductViewModel()