Browse Source

fix methods and properties name following Swift 3

yosuke.a.imairi 9 years ago
parent
commit
596b4f4091

+ 3 - 3
Sources/AnimatedImageView.swift

@@ -107,17 +107,17 @@ public class AnimatedImageView: UIImageView {
         }
     }
     
-    override public func isAnimating() -> Bool {
+    override public var isAnimating: Bool {
         if displayLinkInitialized {
             return !displayLink.isPaused
         } else {
-            return super.isAnimating()
+            return super.isAnimating
         }
     }
     
     /// Starts the animation.
     override public func startAnimating() {
-        if self.isAnimating() {
+        if self.isAnimating {
             return
         } else {
             displayLink.isPaused = false

+ 5 - 8
Sources/ImageCache.swift

@@ -73,7 +73,7 @@ public enum CacheType {
 public class ImageCache {
 
     //Memory
-    private let memoryCache = Cache<NSString, AnyObject>()
+    private let memoryCache = NSCache<NSString, AnyObject>()
     
     /// The largest cache cost of memory cache. The total cost is pixel count of all cached images in memory.
     public var maxMemoryCost: UInt = 0 {
@@ -123,8 +123,8 @@ public class ImageCache {
         let dstPath = path ?? NSSearchPathForDirectoriesInDomains(.cachesDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).first!
         diskCachePath = (dstPath as NSString).appendingPathComponent(cacheName)
         
-        ioQueue = DispatchQueue(label: ioQueueName + name, attributes: DispatchQueueAttributes.serial)
-        processQueue = DispatchQueue(label: processQueueName + name, attributes: DispatchQueueAttributes.concurrent)
+        ioQueue = DispatchQueue(label: ioQueueName + name, attributes: DispatchQueue.Attributes.concurrent)
+        processQueue = DispatchQueue(label: processQueueName + name, attributes: DispatchQueue.Attributes.concurrent)
         
         ioQueue.sync(execute: { () -> Void in
             self.fileManager = FileManager()
@@ -423,7 +423,7 @@ extension ImageCache {
                 
                 if URLsToDelete.count != 0 {
                     let cleanedHashes = URLsToDelete.map({ (url) -> String in
-                        return url.lastPathComponent!
+                        return url.lastPathComponent
                     })
                     
                     NotificationCenter.default.post(name: KingfisherDidCleanDiskCacheNotification, object: self, userInfo: [KingfisherDiskCacheCleanedHashKey: cleanedHashes])
@@ -444,10 +444,7 @@ extension ImageCache {
         var URLsToDelete = [URL]()
         var diskCacheSize: UInt = 0
         
-        let resourceKeysString = resourceKeys.map { (key) -> String in
-            return key.rawValue
-        }
-        if let fileEnumerator = self.fileManager.enumerator(at: diskCacheURL, includingPropertiesForKeys: resourceKeysString, options: FileManager.DirectoryEnumerationOptions.skipsHiddenFiles, errorHandler: nil),
+        if let fileEnumerator = self.fileManager.enumerator(at: diskCacheURL, includingPropertiesForKeys: resourceKeys, options: FileManager.DirectoryEnumerationOptions.skipsHiddenFiles, errorHandler: nil),
             let urls = fileEnumerator.allObjects as? [URL] {
                 for fileURL in urls {
                     

+ 3 - 3
Sources/ImageDownloader.swift

@@ -201,8 +201,8 @@ public class ImageDownloader: NSObject {
             fatalError("[Kingfisher] You should specify a name for the downloader. A downloader with empty name is not permitted.")
         }
         
-        barrierQueue = DispatchQueue(label: downloaderBarrierName + name, attributes: DispatchQueueAttributes.concurrent)
-        processQueue = DispatchQueue(label: imageProcessQueueName + name, attributes: DispatchQueueAttributes.concurrent)
+        barrierQueue = DispatchQueue(label: downloaderBarrierName + name, attributes: DispatchQueue.Attributes.concurrent)
+        processQueue = DispatchQueue(label: imageProcessQueueName + name, attributes: DispatchQueue.Attributes.concurrent)
         
         sessionHandler = ImageDownloaderSessionHandler()
         
@@ -284,7 +284,7 @@ extension ImageDownloader {
         self.requestModifier?(request)
         
         // There is a possiblility that request modifier changed the url to `nil` or empty.
-        if request.url == nil || (request.url!.absoluteString?.isEmpty)! {
+        if request.url == nil || request.url!.absoluteString.isEmpty {
             completionHandler?(image: nil, error: NSError(domain: KingfisherErrorDomain, code: KingfisherError.invalidURL.rawValue, userInfo: nil), imageURL: nil, originalData: nil)
             return nil
         }

+ 1 - 1
Sources/Resource.swift

@@ -49,6 +49,6 @@ public struct Resource {
      */
     public init(downloadURL: URL, cacheKey: String? = nil) {
         self.downloadURL = downloadURL
-        self.cacheKey = cacheKey ?? downloadURL.absoluteString!
+        self.cacheKey = cacheKey ?? downloadURL.absoluteString
     }
 }

+ 2 - 2
Sources/String+MD5.swift

@@ -43,7 +43,7 @@ extension String {
 func arrayOfBytes<T>(_ value: T, length: Int? = nil) -> [UInt8] {
     let totalBytes = length ?? (sizeofValue(value) * 8)
     
-    let valuePointer = UnsafeMutablePointer<T>(allocatingCapacity: 1)
+    let valuePointer = UnsafeMutablePointer<T>.allocate(capacity: 1)
     valuePointer.pointee = value
     
     let bytesPointer = UnsafeMutablePointer<UInt8>(valuePointer)
@@ -53,7 +53,7 @@ func arrayOfBytes<T>(_ value: T, length: Int? = nil) -> [UInt8] {
     }
     
     valuePointer.deinitialize()
-    valuePointer.deallocateCapacity(1)
+    valuePointer.deallocate(capacity: 1)
     
     return bytes
 }