Skip to content

Commit

Permalink
Fix warnings in Swift 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
onevcat committed Mar 28, 2017
1 parent a53f6f9 commit f9a9b1f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
24 changes: 12 additions & 12 deletions Tests/KingfisherTests/ImageCacheTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ImageCacheTests: XCTestCase {
let expectation = self.expectation(description: "wait for clearing disk cache")
let key = testKeys[0]

cache.store(testImage, original: testImageData as? Data, forKey: key, toDisk: true) { () -> () in
cache.store(testImage, original: testImageData as Data?, forKey: key, toDisk: true) { () -> () in
self.cache.clearMemoryCache()
let cacheResult = self.cache.isImageCached(forKey: key)
XCTAssertTrue(cacheResult.cached, "Should be cached")
Expand All @@ -94,7 +94,7 @@ class ImageCacheTests: XCTestCase {
func testClearMemoryCache() {
let expectation = self.expectation(description: "wait for retrieving image")

cache.store(testImage, original: testImageData as? Data, forKey: testKeys[0], toDisk: true) { () -> () in
cache.store(testImage, original: testImageData as Data?, forKey: testKeys[0], toDisk: true) { () -> () in
self.cache.clearMemoryCache()
self.cache.retrieveImage(forKey: testKeys[0], options: nil, completionHandler: { (image, type) -> () in
XCTAssert(image != nil && type == .disk, "Should be cached in disk. But \(type)")
Expand Down Expand Up @@ -145,7 +145,7 @@ class ImageCacheTests: XCTestCase {
} catch _ {
files = nil
}
XCTAssert(files?.count == 4, "All test images should be at locaitons. Expected 4, actually \(files?.count)")
XCTAssert(files?.count == 4, "All test images should be at locaitons. Expected 4, actually \(String(describing: files?.count))")

expectation.fulfill()
}
Expand Down Expand Up @@ -263,7 +263,7 @@ class ImageCacheTests: XCTestCase {
let expectation = self.expectation(description: "wait for caching image")

XCTAssert(self.cache.isImageCached(forKey: testKeys[0]).cached == false, "This image should not be cached yet.")
self.cache.store(testImage, original: testImageData as? Data, forKey: testKeys[0], toDisk: true) { () -> () in
self.cache.store(testImage, original: testImageData as Data?, forKey: testKeys[0], toDisk: true) { () -> () in
XCTAssert(self.cache.isImageCached(forKey: testKeys[0]).cached == true, "This image should be already cached.")
expectation.fulfill()
}
Expand All @@ -274,7 +274,7 @@ class ImageCacheTests: XCTestCase {
func testRetrievingImagePerformance() {

let expectation = self.expectation(description: "wait for retrieving image")
self.cache.store(testImage, original: testImageData as? Data, forKey: testKeys[0], toDisk: true) { () -> () in
self.cache.store(testImage, original: testImageData as Data?, forKey: testKeys[0], toDisk: true) { () -> () in
self.measure({ () -> Void in
for _ in 1 ..< 200 {
_ = self.cache.retrieveImageInDiskCache(forKey: testKeys[0])
Expand All @@ -289,7 +289,7 @@ class ImageCacheTests: XCTestCase {
func testCleanDiskCacheNotification() {
let expectation = self.expectation(description: "wait for retrieving image")

cache.store(testImage, original: testImageData as? Data, forKey: testKeys[0], toDisk: true) { () -> () in
cache.store(testImage, original: testImageData as Data?, forKey: testKeys[0], toDisk: true) { () -> () in

self.observer = NotificationCenter.default.addObserver(forName: .KingfisherDidCleanDiskCache, object: self.cache, queue: OperationQueue.main, using: { (noti) -> Void in

Expand Down Expand Up @@ -321,7 +321,7 @@ class ImageCacheTests: XCTestCase {
let expectation = self.expectation(description: "wait for retrieving image")
let p = RoundCornerImageProcessor(cornerRadius: 40)

cache.store(testImage, original: testImageData as? Data, forKey: testKeys[0], toDisk: true) { () -> () in
cache.store(testImage, original: testImageData as Data?, forKey: testKeys[0], toDisk: true) { () -> () in

self.cache.retrieveImage(forKey: testKeys[0], options: [.processor(p)], completionHandler: { (image, type) -> () in

Expand All @@ -338,7 +338,7 @@ class ImageCacheTests: XCTestCase {
let expectation = self.expectation(description: "wait for retrieving image")
let p = RoundCornerImageProcessor(cornerRadius: 40)

cache.store(testImage, original: testImageData as? Data, forKey: testKeys[0], processorIdentifier: p.identifier,toDisk: true) { () -> () in
cache.store(testImage, original: testImageData as Data?, forKey: testKeys[0], processorIdentifier: p.identifier,toDisk: true) { () -> () in

self.cache.retrieveImage(forKey: testKeys[0], options: [.processor(p)], completionHandler: { (image, type) -> () in

Expand All @@ -357,19 +357,19 @@ class ImageCacheTests: XCTestCase {
let group = DispatchGroup()

group.enter()
cache.store(testImage, original: testImageData as? Data, forKey: testKeys[0], toDisk: true) { () -> () in
cache.store(testImage, original: testImageData as Data?, forKey: testKeys[0], toDisk: true) { () -> () in
group.leave()
}
group.enter()
cache.store(testImage, original: testImageData as? Data, forKey: testKeys[1], toDisk: true) { () -> () in
cache.store(testImage, original: testImageData as Data?, forKey: testKeys[1], toDisk: true) { () -> () in
group.leave()
}
group.enter()
cache.store(testImage, original: testImageData as? Data, forKey: testKeys[2], toDisk: true) { () -> () in
cache.store(testImage, original: testImageData as Data?, forKey: testKeys[2], toDisk: true) { () -> () in
group.leave()
}
group.enter()
cache.store(testImage, original: testImageData as? Data, forKey: testKeys[3], toDisk: true) { () -> () in
cache.store(testImage, original: testImageData as Data?, forKey: testKeys[3], toDisk: true) { () -> () in
group.leave()
}

Expand Down
14 changes: 7 additions & 7 deletions Tests/KingfisherTests/ImageDownloaderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ImageDownloaderTests: XCTestCase {
return
}) { (image, error, imageURL, data) -> () in
expectation.fulfill()
XCTAssert(image != nil, "Download should be able to finished for URL: \(imageURL)")
XCTAssert(image != nil, "Download should be able to finished for URL: \(String(describing: imageURL))")
}

waitForExpectations(timeout: 5, handler: nil)
Expand All @@ -86,7 +86,7 @@ class ImageDownloaderTests: XCTestCase {
downloader.downloadImage(with: url, options: nil, progressBlock: { (receivedSize, totalSize) -> () in

}, completionHandler: { (image, error, imageURL, data) -> () in
XCTAssert(image != nil, "Download should be able to finished for URL: \(imageURL).")
XCTAssert(image != nil, "Download should be able to finished for URL: \(String(describing: imageURL)).")
group.leave()
})
}
Expand All @@ -111,7 +111,7 @@ class ImageDownloaderTests: XCTestCase {
downloader.downloadImage(with: URL(string: URLString)!, options: nil, progressBlock: { (receivedSize, totalSize) -> () in

}) { (image, error, imageURL, data) -> () in
XCTAssert(image != nil, "Download should be able to finished for URL: \(imageURL).")
XCTAssert(image != nil, "Download should be able to finished for URL: \(String(describing: imageURL)).")
group.leave()

}
Expand All @@ -136,7 +136,7 @@ class ImageDownloaderTests: XCTestCase {
downloader.downloadImage(with: someURL, options: [.requestModifier(modifier)], progressBlock: { (receivedSize, totalSize) -> () in

}) { (image, error, imageURL, data) -> () in
XCTAssert(image != nil, "Download should be able to finished for URL: \(imageURL).")
XCTAssert(image != nil, "Download should be able to finished for URL: \(String(describing: imageURL)).")
XCTAssertEqual(imageURL!, URL(string: URLString)!, "The returned imageURL should be the replaced one")
expectation.fulfill()
}
Expand Down Expand Up @@ -189,13 +189,13 @@ class ImageDownloaderTests: XCTestCase {

downloader.downloadImage(with: url, progressBlock: nil, completionHandler: { (image, error, imageURL, data) -> () in
XCTAssertNotNil(error, "Error should not be nil")
XCTAssert(error?.code == NSURLErrorServerCertificateUntrusted || error?.code == NSURLErrorSecureConnectionFailed, "Error should be NSURLErrorServerCertificateUntrusted, but \(error)")
XCTAssert(error?.code == NSURLErrorServerCertificateUntrusted || error?.code == NSURLErrorSecureConnectionFailed, "Error should be NSURLErrorServerCertificateUntrusted, but \(String(describing: error))")
expectation.fulfill()
LSNocilla.sharedInstance().start()
})

waitForExpectations(timeout: 20) { (error) in
XCTAssertNil(error, "\(error)")
XCTAssertNil(error, "\(String(describing: error))")
LSNocilla.sharedInstance().start()
}
}
Expand Down Expand Up @@ -308,7 +308,7 @@ class ImageDownloaderTests: XCTestCase {

}) { (image, error, imageURL, data) -> () in
expectation.fulfill()
XCTAssert(image != nil, "Download should be able to finished for URL: \(imageURL)")
XCTAssert(image != nil, "Download should be able to finished for URL: \(String(describing: imageURL))")
XCTAssertFalse(image!.renderEqual(to: testImage), "The processed image should not equal to the original one.")
XCTAssertTrue(image!.renderEqual(to: roundcornered), "The processed image should equal to the one directly processed from original one.")
XCTAssertEqual(NSData(data: data!), testImageData, "But the original data should equal each other.")
Expand Down
2 changes: 1 addition & 1 deletion Tests/KingfisherTests/ImageViewExtensionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ class ImageViewExtensionTests: XCTestCase {

func testCanUseImageIndicatorViewAnimating() {

imageView.kf.indicatorType = .image(imageData: testImageData as! Data)
imageView.kf.indicatorType = .image(imageData: testImageData! as Data)
XCTAssertTrue(imageView.kf.indicator is ImageIndicator)
let image = (imageView.kf.indicator?.view as? ImageView)?.image
XCTAssertNotNil(image)
Expand Down

0 comments on commit f9a9b1f

Please sign in to comment.