Last active
August 29, 2015 14:20
-
-
Save sidraval/614cd09b5c6b3385d634 to your computer and use it in GitHub Desktop.
ProductController
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
// ProductDelegate | |
import UIKit | |
protocol ProductDelegate: NSObjectProtocol { | |
func didReceiveProduct(product: Product) | |
func didReceiveProductImage(image: UIImage) | |
} | |
// ProductController | |
struct ProductController { | |
let product: Product | |
let productFetcher: ProductFetcher | |
weak var productDelegate: ProductDelegate? | |
init(product: Product, productDelegate: ProductDelegate, productFetcher: ProductFetcher = ProductClient()) { | |
self.product = product | |
self.productFetcher = productFetcher | |
self.productDelegate = productDelegate | |
} | |
func fetchProductData() { | |
productFetcher.fetchDataFor(product: product) { product in | |
self.productDelegate?.didReceiveProduct(product) | |
} | |
} | |
func fetchProductImage(imageUrl: String?) { | |
if let url = imageUrl { | |
productFetcher.fetchImageFor(url) { image in | |
self.productDelegate?.didReceiveProductImage(image) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment