Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 5.0 support #1098

Merged
merged 22 commits into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
language: swift
osx_image: xcode10.1

osx_image:
- xcode10.1
- xcode10.2

env:
- SCHEME=Kingfisher SWIFT_VERSION=5.0
- SCHEME=Kingfisher-macOS SWIFT_VERSION=5.0
- SCHEME=Kingfisher-tvOS SWIFT_VERSION=5.0
- SCHEME=Kingfisher SWIFT_VERSION=4.2
- SCHEME=Kingfisher-macOS SWIFT_VERSION=4.2
- SCHEME=Kingfisher-tvOS SWIFT_VERSION=4.2
- SCHEME=Kingfisher SWIFT_VERSION=4.0
- SCHEME=Kingfisher-macOS SWIFT_VERSION=4.0
- SCHEME=Kingfisher-tvOS SWIFT_VERSION=4.0

cache: bundler

Expand All @@ -8,19 +22,13 @@ before_install:
- gem install bundler

matrix:
include:
- name: iOS | Swift 4.2
env: LANE=test_ci SCHEME=Kingfisher SWIFT_VERSION=4.2
- name: macOS | Swift 4.2
env: LANE=test_ci SCHEME=Kingfisher-macOS SWIFT_VERSION=4.2
- name: tvOS | Swift 4.2
env: LANE=test_ci SCHEME=Kingfisher-tvOS SWIFT_VERSION=4.2
- name: iOS | Swift 4.0
env: LANE=test_ci SCHEME=Kingfisher SWIFT_VERSION=4.0
- name: macOS | Swift 4.0
env: LANE=test_ci SCHEME=Kingfisher-macOS SWIFT_VERSION=4.0
- name: tvOS | Swift 4.0
env: LANE=test_ci SCHEME=Kingfisher-tvOS SWIFT_VERSION=4.0
exclude:
- osx_image: xcode10.1
env: SCHEME=Kingfisher SWIFT_VERSION=5.0
- osx_image: xcode10.1
env: SCHEME=Kingfisher-macOS SWIFT_VERSION=5.0
- osx_image: xcode10.1
env: SCHEME=Kingfisher-tvOS SWIFT_VERSION=5.0

script:
- bundle exec fastlane $LANE
- bundle exec fastlane test_ci
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class DetailImageViewController: UIViewController {
scrollView.delegate = self

imageView.kf.setImage(with: imageURL, options: [.memoryCacheExpiration(.expired)]) { result in
guard let image = result.value?.image else {
guard let image = try? result.get().image else {
return
}
let scrollViewFrame = self.scrollView.frame
Expand Down
10 changes: 0 additions & 10 deletions Demo/Kingfisher-Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,6 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = macosx;
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
};
name = Debug;
};
Expand All @@ -721,7 +720,6 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
};
name = Release;
};
Expand All @@ -741,7 +739,6 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = appletvos;
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
TARGETED_DEVICE_FAMILY = 3;
};
name = Debug;
Expand All @@ -763,7 +760,6 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = appletvos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
TARGETED_DEVICE_FAMILY = 3;
};
name = Release;
Expand All @@ -782,7 +778,6 @@
SDKROOT = watchos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
TARGETED_DEVICE_FAMILY = 4;
};
name = Debug;
Expand All @@ -801,7 +796,6 @@
SDKROOT = watchos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
TARGETED_DEVICE_FAMILY = 4;
};
name = Release;
Expand All @@ -824,7 +818,6 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = watchos;
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
TARGETED_DEVICE_FAMILY = 4;
};
name = Debug;
Expand All @@ -847,7 +840,6 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = watchos;
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
TARGETED_DEVICE_FAMILY = 4;
};
name = Release;
Expand Down Expand Up @@ -973,7 +965,6 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.onevcat.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
};
name = Debug;
};
Expand All @@ -988,7 +979,6 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.onevcat.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
};
name = Release;
};
Expand Down
6 changes: 4 additions & 2 deletions Kingfisher.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -859,11 +859,11 @@
};
D1ED2D341AD2D09F00CFC3EB = {
CreatedOnToolsVersion = 6.2;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
};
D1ED2D3E1AD2D09F00CFC3EB = {
CreatedOnToolsVersion = 6.2;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
};
};
};
Expand Down Expand Up @@ -1413,6 +1413,7 @@
SDKROOT = appletvos;
SWIFT_OBJC_BRIDGING_HEADER = "Tests/KingfisherTests/KingfisherTests-Bridging-Header.h";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
TARGETED_DEVICE_FAMILY = 3;
};
name = Debug;
};
Expand All @@ -1431,6 +1432,7 @@
SWIFT_OBJC_BRIDGING_HEADER = "Tests/KingfisherTests/KingfisherTests-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
TARGETED_DEVICE_FAMILY = 3;
};
name = Release;
};
Expand Down
1 change: 1 addition & 0 deletions Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<a href="#sponsors" alt="Sponsors on Open Collective"><img src="https://opencollective.com/Kingfisher/sponsors/badge.svg" /></a>
</p>

Kingfisher is a powerful, pure-Swift library for downloading and caching images from the web. It provides you a chance to use a pure-Swift alternative in your next app.
Kingfisher is a powerful, pure-Swift library for downloading and caching images from the web. It provides you a chance to use a pure-Swift way to work with remote images in your next app.

## Features

Expand Down Expand Up @@ -78,7 +78,7 @@ imageView.kf.setImage(
}
```

It is really a very common situation I will meet in my daily work. Think about how many lines you need to write if without Kingfisher. You will fall in love with it!
It is really a very common situation I can meet in my daily work. Think about how many lines you need to write without Kingfisher. You will fall in love with it if you give it a try!

### Learn More

Expand Down
12 changes: 9 additions & 3 deletions Sources/Extensions/ImageView+Kingfisher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,14 @@ extension KingfisherWrapper where Base: ImageView {
CallbackQueue.mainCurrentOrAsync.execute {
maybeIndicator?.stopAnimatingView()
guard issuedIdentifier == self.taskIdentifier else {
let error = KingfisherError.imageSettingError(
reason: .notCurrentSourceTask(result: result.value, error: result.error, source: source))
let reason: KingfisherError.ImageSettingErrorReason
do {
let value = try result.get()
reason = .notCurrentSourceTask(result: value, error: nil, source: source)
} catch {
reason = .notCurrentSourceTask(result: nil, error: error, source: source)
}
let error = KingfisherError.imageSettingError(reason: reason)
completionHandler?(.failure(error))
return
}
Expand Down Expand Up @@ -380,7 +386,7 @@ extension KingfisherWrapper where Base: ImageView {

extension KingfisherWrapper where Base: ImageView {
/// Gets the image URL bound to this image view.
@available(*, obsoleted: 5.0, message: "Use `taskIdentifier` instead to identify a setting task.")
@available(*, deprecated, message: "Use `taskIdentifier` instead to identify a setting task.")
public private(set) var webURL: URL? {
get { return nil }
set { }
Expand Down
4 changes: 2 additions & 2 deletions Sources/Extensions/NSButton+Kingfisher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,15 @@ extension KingfisherWrapper where Base: NSButton {
extension KingfisherWrapper where Base: NSButton {

/// Gets the image URL bound to this button.
@available(*, obsoleted: 5.0, message: "Use `taskIdentifier` instead to identify a setting task.")
@available(*, deprecated, message: "Use `taskIdentifier` instead to identify a setting task.")
public private(set) var webURL: URL? {
get { return nil }
set { }
}


/// Gets the image URL bound to this button.
@available(*, obsoleted: 5.0, message: "Use `alternateTaskIdentifier` instead to identify a setting task.")
@available(*, deprecated, message: "Use `alternateTaskIdentifier` instead to identify a setting task.")
public private(set) var alternateWebURL: URL? {
get { return nil }
set { }
Expand Down
24 changes: 18 additions & 6 deletions Sources/Extensions/UIButton+Kingfisher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,14 @@ extension KingfisherWrapper where Base: UIButton {
completionHandler: { result in
CallbackQueue.mainCurrentOrAsync.execute {
guard issuedTaskIdentifier == self.taskIdentifier(for: state) else {
let error = KingfisherError.imageSettingError(
reason: .notCurrentSourceTask(result: result.value, error: result.error, source: source))
let reason: KingfisherError.ImageSettingErrorReason
do {
let value = try result.get()
reason = .notCurrentSourceTask(result: value, error: nil, source: source)
} catch {
reason = .notCurrentSourceTask(result: nil, error: error, source: source)
}
let error = KingfisherError.imageSettingError(reason: reason)
completionHandler?(.failure(error))
return
}
Expand Down Expand Up @@ -205,8 +211,14 @@ extension KingfisherWrapper where Base: UIButton {
completionHandler: { result in
CallbackQueue.mainCurrentOrAsync.execute {
guard issuedTaskIdentifier == self.backgroundTaskIdentifier(for: state) else {
let error = KingfisherError.imageSettingError(
reason: .notCurrentSourceTask(result: result.value, error: result.error, source: source))
let reason: KingfisherError.ImageSettingErrorReason
do {
let value = try result.get()
reason = .notCurrentSourceTask(result: value, error: nil, source: source)
} catch {
reason = .notCurrentSourceTask(result: nil, error: error, source: source)
}
let error = KingfisherError.imageSettingError(reason: reason)
completionHandler?(.failure(error))
return
}
Expand Down Expand Up @@ -351,7 +363,7 @@ extension KingfisherWrapper where Base: UIButton {
///
/// - Parameter state: The state that uses the specified image.
/// - Returns: Current URL for image.
@available(*, obsoleted: 5.0, message: "Use `taskIdentifier` instead to identify a setting task.")
@available(*, deprecated, message: "Use `taskIdentifier` instead to identify a setting task.")
public func webURL(for state: UIControl.State) -> URL? {
return nil
}
Expand All @@ -360,7 +372,7 @@ extension KingfisherWrapper where Base: UIButton {
///
/// - Parameter state: The state that uses the specified background image.
/// - Returns: Current URL for image.
@available(*, obsoleted: 5.0, message: "Use `backgroundTaskIdentifier` instead to identify a setting task.")
@available(*, deprecated, message: "Use `backgroundTaskIdentifier` instead to identify a setting task.")
public func backgroundWebURL(for state: UIControl.State) -> URL? {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Extensions/WKInterfaceImage+Kingfisher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ extension KingfisherWrapper where Base: WKInterfaceImage {

extension KingfisherWrapper where Base: WKInterfaceImage {
/// Gets the image URL bound to this image view.
@available(*, obsoleted: 5.0, message: "Use `taskIdentifier` instead to identify a setting task.")
@available(*, deprecated, message: "Use `taskIdentifier` instead to identify a setting task.")
public private(set) var webURL: URL? {
get { return nil }
set { }
Expand Down
14 changes: 10 additions & 4 deletions Sources/General/Deprecated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,12 @@ extension ImageCache {
callbackQueue: .dispatch((options ?? .empty).callbackDispatchQueue))
{
result in
completionHandler?(result.value?.image, result.value?.cacheType ?? .none)
do {
let value = try result.get()
completionHandler?(value.image, value.cacheType)
} catch {
completionHandler?(nil, .none)
}
}
}

Expand Down Expand Up @@ -430,13 +435,14 @@ extension ImageCache {
@available(*, deprecated, message: "Use the `Result`-based `calculateDiskStorageSize` instead.")
open func calculateDiskCacheSize(completion handler: @escaping ((_ size: UInt) -> Void)) {
calculateDiskStorageSize { result in
handler(result.value ?? 0)
let size: UInt? = try? result.get()
handler(size ?? 0)
}
}
}

// MARK: - Deprecated
public extension Collection where Iterator.Element == KingfisherOptionsInfoItem {
extension Collection where Iterator.Element == KingfisherOptionsInfoItem {
/// The queue of callbacks should happen from Kingfisher.
@available(*, deprecated, message: "Use `callbackQueue` instead.", renamed: "callbackQueue")
public var callbackDispatchQueue: DispatchQueue {
Expand All @@ -454,7 +460,7 @@ message: "Use `.invalidHTTPStatusCode` or `isInvalidResponseStatusCode` of `King
public let KingfisherErrorStatusCodeKey = "statusCode"

// MARK: - Deprecated
public extension Collection where Iterator.Element == KingfisherOptionsInfoItem {
extension Collection where Iterator.Element == KingfisherOptionsInfoItem {
/// The target `ImageCache` which is used.
@available(*, deprecated,
message: "Create a `KingfisherParsedOptionsInfo` from `KingfisherOptionsInfo` and use `targetCache` instead.")
Expand Down
2 changes: 1 addition & 1 deletion Sources/General/ImageSource/ImageDataProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public struct LocalFileImageDataProvider: ImageDataProvider {
public var cacheKey: String

public func data(handler: (Result<Data, Error>) -> Void) {
handler( Result { try Data(contentsOf: fileURL) } )
handler(Result(catching: { try Data(contentsOf: fileURL) }))
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/General/Kingfisher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public struct KingfisherWrapper<Base> {
/// value in the namespace of Kingfisher.
public protocol KingfisherCompatible { }

public extension KingfisherCompatible {
extension KingfisherCompatible {

/// Gets a namespace holder for Kingfisher compatible types.
public var kf: KingfisherWrapper<Self> {
Expand Down
2 changes: 1 addition & 1 deletion Sources/General/KingfisherError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import Foundation

extension Never: Error {}
extension Never {}

/// Represents all the errors which can happen in Kingfisher framework.
/// Kingfisher related methods always throw a `KingfisherError` or invoke the callback with `KingfisherError`
Expand Down
Loading