Skip to content

Commit

Permalink
Use less generic multiplatform type
Browse files Browse the repository at this point in the history
  • Loading branch information
3lvis committed May 14, 2016
1 parent bbf1c29 commit 06ba5cf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
10 changes: 5 additions & 5 deletions Sources/Networking+Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ public extension Networking {
- parameter cacheName: The cache name used to identify the downloaded image, by default the path is used.
- parameter completion: A closure that returns the image from the cache, if no image is found it will return nil, it contains a image and a error.
*/
public func imageFromCache(path: String, cacheName: String? = nil, completion: (image: Image?) -> Void) {
public func imageFromCache(path: String, cacheName: String? = nil, completion: (image: NetworkingImage?) -> Void) {
self.objectFromCache(path, cacheName: cacheName, responseType: .Image) { object in
TestCheck.testBlock(disabled: self.disableTestingMode) {
completion(image: object as? Image)
completion(image: object as? NetworkingImage)
}
}
}
Expand All @@ -21,10 +21,10 @@ public extension Networking {
- parameter cacheName: The cache name used to identify the downloaded image, by default the path is used.
- parameter completion: A closure that gets called when the image download request is completed, it contains a image and a error.
*/
public func downloadImage(path: String, cacheName: String? = nil, completion: (image: Image?, error: NSError?) -> Void) {
public func downloadImage(path: String, cacheName: String? = nil, completion: (image: NetworkingImage?, error: NSError?) -> Void) {
self.request(.GET, path: path, cacheName: cacheName, parameterType: nil, parameters: nil, responseType: .Image) { response, error in
TestCheck.testBlock(disabled: self.disableTestingMode) {
completion(image: response as? Image, error: error)
completion(image: response as? NetworkingImage, error: error)
}
}
}
Expand All @@ -43,7 +43,7 @@ public extension Networking {
- parameter path: The path for the faked image download request.
- parameter image: An image that will be returned when there's a request to the registered path.
*/
public func fakeImageDownload(path: String, image: Image?, statusCode: Int = 200) {
public func fakeImageDownload(path: String, image: NetworkingImage?, statusCode: Int = 200) {
self.fake(.GET, path: path, response: image, statusCode: statusCode)
}
}
8 changes: 4 additions & 4 deletions Sources/Networking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import Foundation

#if os(OSX)
import AppKit.NSImage
public typealias Image = NSImage
public typealias NetworkingImage = NSImage
#else
import UIKit.UIImage
public typealias Image = UIImage
public typealias NetworkingImage = UIImage
#endif

public extension Int {
Expand Down Expand Up @@ -284,7 +284,7 @@ extension Networking {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0)) {
let object = self.dataForDestinationURL(destinationURL)
if responseType == .Image {
returnedObject = Image(data: object)
returnedObject = NetworkingImage(data: object)
} else {
returnedObject = object
}
Expand Down Expand Up @@ -390,7 +390,7 @@ extension Networking {
returnedResponse = data
break
case .Image:
if let image = Image(data: data) {
if let image = NetworkingImage(data: data) {
self.cache.setObject(image, forKey: destinationURL.absoluteString)
returnedResponse = image
}
Expand Down
26 changes: 13 additions & 13 deletions Tests/ImageTests.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Foundation
import XCTest

extension Image {
static func find(named name: String, inBundle bundle: NSBundle) -> Image {
extension NetworkingImage {
static func find(named name: String, inBundle bundle: NSBundle) -> NetworkingImage {
#if os(OSX)
return bundle.imageForResource(name)!
#else
Expand Down Expand Up @@ -58,7 +58,7 @@ class ImageTests: XCTestCase {
Helper.removeFileIfNeeded(networking, path: path)

networking.downloadImage(path) { image, error in
let pigImage = Image.find(named: "pig.png", inBundle: NSBundle(forClass: ImageTests.self))
let pigImage = NetworkingImage.find(named: "pig.png", inBundle: NSBundle(forClass: ImageTests.self))
let pigImageData = pigImage.PNGData()
let imageData = image!.PNGData()
XCTAssertEqual(pigImageData, imageData)
Expand All @@ -72,7 +72,7 @@ class ImageTests: XCTestCase {
Helper.removeFileIfNeeded(networking, path: path)

networking.downloadImage(path) { image, error in
let pigImage = Image.find(named: "døgnvillburgere.jpg", inBundle: NSBundle(forClass: ImageTests.self))
let pigImage = NetworkingImage.find(named: "døgnvillburgere.jpg", inBundle: NSBundle(forClass: ImageTests.self))
let pigImageData = pigImage.PNGData()
let imageData = image!.PNGData()
XCTAssertEqual(pigImageData, imageData)
Expand Down Expand Up @@ -116,8 +116,8 @@ class ImageTests: XCTestCase {

networking.downloadImage(path) { image, error in
let destinationURL = try! networking.destinationURL(path)
let image = networking.cache.objectForKey(destinationURL.absoluteString) as! Image
let pigImage = Image.find(named: "pig.png", inBundle: NSBundle(forClass: ImageTests.self))
let image = networking.cache.objectForKey(destinationURL.absoluteString) as! NetworkingImage
let pigImage = NetworkingImage.find(named: "pig.png", inBundle: NSBundle(forClass: ImageTests.self))
let pigImageData = pigImage.PNGData()
let imageData = image.PNGData()
XCTAssertEqual(pigImageData, imageData)
Expand All @@ -133,8 +133,8 @@ class ImageTests: XCTestCase {

networking.downloadImage(path, cacheName: cacheName) { image, error in
let destinationURL = try! networking.destinationURL(path, cacheName: cacheName)
let image = networking.cache.objectForKey(destinationURL.absoluteString) as! Image
let pigImage = Image.find(named: "pig.png", inBundle: NSBundle(forClass: ImageTests.self))
let image = networking.cache.objectForKey(destinationURL.absoluteString) as! NetworkingImage
let pigImage = NetworkingImage.find(named: "pig.png", inBundle: NSBundle(forClass: ImageTests.self))
let pigImageData = pigImage.PNGData()
let imageData = image.PNGData()
XCTAssertEqual(pigImageData, imageData)
Expand Down Expand Up @@ -162,7 +162,7 @@ class ImageTests: XCTestCase {

func testFakeImageDownload() {
let networking = Networking(baseURL: baseURL)
let pigImage = Image.find(named: "pig.png", inBundle: NSBundle(forClass: ImageTests.self))
let pigImage = NetworkingImage.find(named: "pig.png", inBundle: NSBundle(forClass: ImageTests.self))
networking.fakeImageDownload("/image/png", image: pigImage)
networking.downloadImage("/image/png") { image, error in
let pigImageData = pigImage.PNGData()
Expand Down Expand Up @@ -199,7 +199,7 @@ class ImageTests: XCTestCase {
networking.downloadImage(path) { image, error in
networking.imageFromCache(path) { image in
synchronous = true
let pigImage = Image.find(named: "pig.png", inBundle: NSBundle(forClass: ImageTests.self))
let pigImage = NetworkingImage.find(named: "pig.png", inBundle: NSBundle(forClass: ImageTests.self))
let pigImageData = pigImage.PNGData()
let imageData = image!.PNGData()
XCTAssertEqual(pigImageData, imageData)
Expand All @@ -218,7 +218,7 @@ class ImageTests: XCTestCase {
networking.downloadImage(path, cacheName: cacheName) { _, _ in
networking.imageFromCache(path, cacheName: cacheName) { image in
synchronous = true
let pigImage = Image.find(named: "pig.png", inBundle: NSBundle(forClass: ImageTests.self))
let pigImage = NetworkingImage.find(named: "pig.png", inBundle: NSBundle(forClass: ImageTests.self))
let pigImageData = pigImage.PNGData()
let imageData = image!.PNGData()
XCTAssertEqual(pigImageData, imageData)
Expand All @@ -239,7 +239,7 @@ class ImageTests: XCTestCase {
cache.removeObjectForKey(destinationURL.absoluteString)
networking.imageFromCache(path) { image in
synchronous = true
let pigImage = Image.find(named: "pig.png", inBundle: NSBundle(forClass: ImageTests.self))
let pigImage = NetworkingImage.find(named: "pig.png", inBundle: NSBundle(forClass: ImageTests.self))
let pigImageData = pigImage.PNGData()
let imageData = image!.PNGData()
XCTAssertEqual(pigImageData, imageData)
Expand All @@ -261,7 +261,7 @@ class ImageTests: XCTestCase {
cache.removeObjectForKey(destinationURL.absoluteString)
networking.imageFromCache(path, cacheName: cacheName) { image in
synchronous = true
let pigImage = Image.find(named: "pig.png", inBundle: NSBundle(forClass: ImageTests.self))
let pigImage = NetworkingImage.find(named: "pig.png", inBundle: NSBundle(forClass: ImageTests.self))
let pigImageData = pigImage.PNGData()
let imageData = image!.PNGData()
XCTAssertEqual(pigImageData, imageData)
Expand Down

0 comments on commit 06ba5cf

Please sign in to comment.