From 9cd65354eb446000dfc34f07eea648eef507c084 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Fri, 27 Dec 2019 11:58:24 +0800 Subject: [PATCH] Support SwiftPM --- .gitignore | 6 +++- Package.resolved | 25 ++++++++++++++ Package.swift | 34 +++++++++++++++++++ .../Classes/SDImageWebPCoder.h | 4 +++ .../Classes/SDImageWebPCoder.m | 8 ++--- SDWebImageWebPCoder/Classes/UIImage+WebP.h | 4 +++ 6 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 Package.resolved create mode 100644 Package.swift diff --git a/.gitignore b/.gitignore index 2228df1..23eaadf 100644 --- a/.gitignore +++ b/.gitignore @@ -64,4 +64,8 @@ fastlane/test_output # After new code Injection tools there's a generated folder /iOSInjectionProject # https://github.com/johnno1962/injectionforxcode -iOSInjectionProject/ \ No newline at end of file +iOSInjectionProject/ + +# SwiftPM +.swiftpm +.build diff --git a/Package.resolved b/Package.resolved new file mode 100644 index 0000000..665c98d --- /dev/null +++ b/Package.resolved @@ -0,0 +1,25 @@ +{ + "object": { + "pins": [ + { + "package": "libwebp", + "repositoryURL": "https://github.com/SDWebImage/libwebp-Xcode.git", + "state": { + "branch": null, + "revision": "cad41dc4f84bbf13bfe2f3acf85c58d1cb316ea0", + "version": "1.1.0-rc2" + } + }, + { + "package": "SDWebImage", + "repositoryURL": "https://github.com/SDWebImage/SDWebImage.git", + "state": { + "branch": null, + "revision": "7ef9a314b12c1a31edb0d09d41fcba93143fe772", + "version": "5.4.0" + } + } + ] + }, + "version": 1 +} diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..b5e389e --- /dev/null +++ b/Package.swift @@ -0,0 +1,34 @@ +// swift-tools-version:5.0 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "SDWebImageWebPCoder", + platforms: [ + .macOS(.v10_13), .iOS(.v8), .tvOS(.v10) + ], + products: [ + // Products define the executables and libraries produced by a package, and make them visible to other packages. + .library( + name: "SDWebImageWebPCoder", + targets: ["SDWebImageWebPCoder"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + .package(url: "https://github.com/SDWebImage/SDWebImage.git", from: "5.1.0"), + .package(url: "https://github.com/SDWebImage/libwebp-Xcode.git", from: Version(1, 1, 0, prereleaseIdentifiers: ["-rc.2"])) + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages which this package depends on. + .target( + name: "SDWebImageWebPCoder", + dependencies: ["SDWebImage", "libwebp"], + path: ".", + sources: ["SDWebImageWebPCoder/Classes"], + publicHeadersPath: "SDWebImageWebPCoder/Classes" + ) + ] +) diff --git a/SDWebImageWebPCoder/Classes/SDImageWebPCoder.h b/SDWebImageWebPCoder/Classes/SDImageWebPCoder.h index ca6e7f2..7629ded 100644 --- a/SDWebImageWebPCoder/Classes/SDImageWebPCoder.h +++ b/SDWebImageWebPCoder/Classes/SDImageWebPCoder.h @@ -6,7 +6,11 @@ * file that was distributed with this source code. */ +#if __has_include() #import +#else +@import SDWebImage; +#endif /** Built in coder that supports WebP and animated WebP diff --git a/SDWebImageWebPCoder/Classes/SDImageWebPCoder.m b/SDWebImageWebPCoder/Classes/SDImageWebPCoder.m index 1ff3b7a..6b06059 100644 --- a/SDWebImageWebPCoder/Classes/SDImageWebPCoder.m +++ b/SDWebImageWebPCoder/Classes/SDImageWebPCoder.m @@ -7,12 +7,6 @@ */ #import "SDImageWebPCoder.h" -#import -#if __has_include() -#import -#endif -#import -#import #if __has_include("webp/decode.h") && __has_include("webp/encode.h") && __has_include("webp/demux.h") && __has_include("webp/mux.h") #import "webp/decode.h" @@ -24,6 +18,8 @@ #import #import #import +#else +@import libwebp; #endif #import diff --git a/SDWebImageWebPCoder/Classes/UIImage+WebP.h b/SDWebImageWebPCoder/Classes/UIImage+WebP.h index 1e4b0f5..068b305 100644 --- a/SDWebImageWebPCoder/Classes/UIImage+WebP.h +++ b/SDWebImageWebPCoder/Classes/UIImage+WebP.h @@ -6,7 +6,11 @@ * file that was distributed with this source code. */ +#if __has_include() #import +#else +@import SDWebImage; +#endif // This category is just use as a convenience method. For more detail control, use methods in `UIImage+MultiFormat.h` or directlly use `SDImageCoder` @interface UIImage (WebP)