Procházet zdrojové kódy

Merge pull request #632 from onevcat/upgrade/swift3.1

Fix warnings in Swift 3.1
Wei Wang před 9 roky
rodič
revize
c3260109b3

+ 1 - 1
.travis.yml

@@ -1,6 +1,6 @@
 language: objective-c
 os: osx
-osx_image: xcode8.2
+osx_image: xcode8.3
 
 env:
   matrix:

+ 12 - 12
Tests/KingfisherTests/ImageCacheTests.swift

@@ -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")
@@ -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)")
@@ -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()
         }
@@ -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()
         }
@@ -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])
@@ -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
 
@@ -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
                 
@@ -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
                 
@@ -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()
         }
         

+ 7 - 7
Tests/KingfisherTests/ImageDownloaderTests.swift

@@ -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)
@@ -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()
                 })
             }
@@ -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()
                     
             }
@@ -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()
         }
@@ -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()
         }
     }
@@ -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.")

+ 1 - 1
Tests/KingfisherTests/ImageViewExtensionTests.swift

@@ -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)