فهرست منبع

Compatible with both swift 2.2 and 2.3

onevcat 9 سال پیش
والد
کامیت
6b37c4efd9

+ 2 - 1
.travis.yml

@@ -25,4 +25,5 @@ after_success:
     if [ "$TEST_TYPE" = iOS ] || [ "$TEST_TYPE" = OSX ] || [ "$TEST_TYPE" = tvOS ]; then
     if [ "$TEST_TYPE" = iOS ] || [ "$TEST_TYPE" = OSX ] || [ "$TEST_TYPE" = tvOS ]; then
       bash <(curl -s https://codecov.io/bash)
       bash <(curl -s https://codecov.io/bash)
     fi
     fi
-    sleep 5
+    sleep 10
+    

+ 9 - 1
Sources/Image.swift

@@ -168,7 +168,11 @@ func ImagePNGRepresentation(image: Image) -> NSData? {
 #if os(OSX)
 #if os(OSX)
     if let cgimage = image.CGImage {
     if let cgimage = image.CGImage {
         let rep = NSBitmapImageRep(CGImage: cgimage)
         let rep = NSBitmapImageRep(CGImage: cgimage)
+        #if swift(>=2.3)
         return rep.representationUsingType(.PNG, properties:[:])
         return rep.representationUsingType(.PNG, properties:[:])
+        #else
+        return rep.representationUsingType(.NSPNGFileType, properties:[:])
+        #endif
     }
     }
     return nil
     return nil
 #else
 #else
@@ -180,7 +184,11 @@ func ImagePNGRepresentation(image: Image) -> NSData? {
 func ImageJPEGRepresentation(image: Image, _ compressionQuality: CGFloat) -> NSData? {
 func ImageJPEGRepresentation(image: Image, _ compressionQuality: CGFloat) -> NSData? {
 #if os(OSX)
 #if os(OSX)
     let rep = NSBitmapImageRep(CGImage: image.CGImage)
     let rep = NSBitmapImageRep(CGImage: image.CGImage)
-    return rep.representationUsingType(.JPEG, properties: [NSImageCompressionFactor: compressionQuality])
+    #if swift(>=2.3)
+        return rep.representationUsingType(.JPEG, properties: [NSImageCompressionFactor: compressionQuality])
+    #else
+        return rep.representationUsingType(.NSJPEGFileType, properties: [NSImageCompressionFactor: compressionQuality])
+    #endif
 #else
 #else
     return UIImageJPEGRepresentation(image, compressionQuality)
     return UIImageJPEGRepresentation(image, compressionQuality)
 #endif
 #endif

+ 6 - 1
Sources/ImageDownloader.swift

@@ -285,7 +285,12 @@ extension ImageDownloader {
         self.requestModifier?(request)
         self.requestModifier?(request)
         
         
         // There is a possiblility that request modifier changed the url to `nil` or empty.
         // There is a possiblility that request modifier changed the url to `nil` or empty.
-        if request.URL == nil || request.URL?.absoluteString == nil || (request.URL?.absoluteString?.isEmpty)! {
+        #if swift(>=2.3)
+        let isEmptyUrl = (request.URL == nil || request.URL!.absoluteString == nil || (request.URL!.absoluteString!.isEmpty))
+        #else
+        let isEmptyUrl = (request.URL == nil || request.URL!.absoluteString.isEmpty)
+        #endif
+        if isEmptyUrl {
             completionHandler?(image: nil, error: NSError(domain: KingfisherErrorDomain, code: KingfisherError.InvalidURL.rawValue, userInfo: nil), imageURL: nil, originalData: nil)
             completionHandler?(image: nil, error: NSError(domain: KingfisherErrorDomain, code: KingfisherError.InvalidURL.rawValue, userInfo: nil), imageURL: nil, originalData: nil)
             return nil
             return nil
         }
         }

+ 5 - 0
Sources/ImageView+Kingfisher.swift

@@ -219,7 +219,12 @@ extension ImageView {
                     
                     
 #if os(OSX)
 #if os(OSX)
                     let indicator = NSProgressIndicator(frame: CGRect(x: 0, y: 0, width: 16, height: 16))
                     let indicator = NSProgressIndicator(frame: CGRect(x: 0, y: 0, width: 16, height: 16))
+    
+                    #if swift(>=2.3)
                     indicator.controlSize = .Small
                     indicator.controlSize = .Small
+                    #else
+                    indicator.controlSize = .SmallControlSize
+                    #endif
                     indicator.style = .SpinningStyle
                     indicator.style = .SpinningStyle
 #else
 #else
     #if os(tvOS)
     #if os(tvOS)

+ 4 - 0
Sources/Resource.swift

@@ -49,6 +49,10 @@ public struct Resource {
      */
      */
     public init(downloadURL: NSURL, cacheKey: String? = nil) {
     public init(downloadURL: NSURL, cacheKey: String? = nil) {
         self.downloadURL = downloadURL
         self.downloadURL = downloadURL
+        #if swift(>=2.3)
         self.cacheKey = cacheKey ?? downloadURL.absoluteString!
         self.cacheKey = cacheKey ?? downloadURL.absoluteString!
+        #else
+        self.cacheKey = cacheKey ?? downloadURL.absoluteString
+        #endif
     }
     }
 }
 }

+ 4 - 0
Tests/KingfisherTests/ImagePrefetcherTests.swift

@@ -76,7 +76,11 @@ class ImagePrefetcherTests: XCTestCase {
                 XCTAssertEqual(completedResources.count, urls.count, "All resources prefetching should be completed.")
                 XCTAssertEqual(completedResources.count, urls.count, "All resources prefetching should be completed.")
                 XCTAssertEqual(progressCalledCount, urls.count, "Progress should be called the same time of download count.")
                 XCTAssertEqual(progressCalledCount, urls.count, "Progress should be called the same time of download count.")
                 for url in urls {
                 for url in urls {
+                    #if swift(>=2.3)
                     XCTAssertTrue(KingfisherManager.sharedManager.cache.isImageCachedForKey(url.absoluteString!).cached)
                     XCTAssertTrue(KingfisherManager.sharedManager.cache.isImageCachedForKey(url.absoluteString!).cached)
+                    #else
+                    XCTAssertTrue(KingfisherManager.sharedManager.cache.isImageCachedForKey(url.absoluteString).cached)
+                    #endif
                 }
                 }
         }
         }