-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
789 additions
and
140 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Foundation | ||
|
||
struct ApplicationContext { | ||
let networkLayer = URLSessionNetworkLayer() | ||
let imageProvider:ImageProvider | ||
|
||
init() { | ||
imageProvider = ImageProvider(networkLayer: networkLayer) | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import UIKit | ||
import ReactiveCocoa | ||
|
||
class ImageProvider { | ||
private let networkLayer:NetworkLayer | ||
var imageCache = NSCache() | ||
|
||
init(networkLayer: NetworkLayer) { | ||
self.networkLayer = networkLayer | ||
} | ||
|
||
func imageFromURL(url: NSURL) -> SignalProducer<UIImage, NoError> { | ||
return SignalProducer { observer, _ in | ||
if let image = self.imageCache.objectForKey(url.absoluteString) as? UIImage { | ||
observer.sendNext(image) | ||
} else { | ||
self.networkLayer.fetchDataFromUrl(url.absoluteString, completion: { result in | ||
if case .Success(let data) = result, let image = UIImage(data: data) { | ||
self.imageCache.setObject(image, forKey: url.absoluteString) | ||
observer.sendNext(image) | ||
} | ||
}) | ||
} | ||
|
||
} | ||
} | ||
} |
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
Oops, something went wrong.