Skip to content

Commit 3ed991c

Browse files
authored
Merge pull request #8 from SDWebImage/project_swiftpm
Support Xcode 11 and Swift Package Manager
2 parents f4e9186 + 6bb51a8 commit 3ed991c

10 files changed

+83
-10
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ Carthage/Build
3434
# `pod install` in .travis.yml
3535
#
3636
Example/Pods
37+
38+
# SwiftPM
39+
.swiftpm
40+
.build

Cartfile.resolved

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
github "SDWebImage/SDWebImage" "5.0.0"
1+
github "SDWebImage/SDWebImage" "5.1.0"

Example/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PODS:
22
- Expecta (1.0.6)
3-
- SDWebImage/Core (5.0.0)
3+
- SDWebImage/Core (5.1.0)
44
- SDWebImagePhotosPlugin (0.2.1):
55
- SDWebImage/Core (~> 5.0)
66

@@ -19,9 +19,9 @@ EXTERNAL SOURCES:
1919

2020
SPEC CHECKSUMS:
2121
Expecta: 3b6bd90a64b9a1dcb0b70aa0e10a7f8f631667d5
22-
SDWebImage: 5de80a0302de9e377e62f47d2fa1304efff0e55f
22+
SDWebImage: fb387001955223213dde14bc08c8b73f371f8d8f
2323
SDWebImagePhotosPlugin: 3a126667559b206b91d6ca6edacdc58dcaa9b2cd
2424

2525
PODFILE CHECKSUM: 60756e45d1da564a14e0e1964ffd639deadc2855
2626

27-
COCOAPODS: 1.6.1
27+
COCOAPODS: 1.7.5

Package.resolved

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// swift-tools-version:5.0
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "SDWebImagePhotosPlugin",
8+
platforms: [
9+
.macOS(.v10_13), .iOS(.v8), .tvOS(.v10)
10+
],
11+
products: [
12+
// Products define the executables and libraries produced by a package, and make them visible to other packages.
13+
.library(
14+
name: "SDWebImagePhotosPlugin",
15+
targets: ["SDWebImagePhotosPlugin"]),
16+
],
17+
dependencies: [
18+
// Dependencies declare other packages that this package depends on.
19+
// .package(url: /* package url */, from: "1.0.0"),
20+
.package(url: "https://github.com/SDWebImage/SDWebImage.git", from: "5.1.0")
21+
],
22+
targets: [
23+
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
24+
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
25+
.target(
26+
name: "SDWebImagePhotosPlugin",
27+
dependencies: ["SDWebImage"],
28+
path: ".",
29+
sources: ["SDWebImagePhotosPlugin/Classes"],
30+
publicHeadersPath: "SDWebImagePhotosPlugin/Classes"
31+
)
32+
]
33+
)

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[![License](https://img.shields.io/cocoapods/l/SDWebImagePhotosPlugin.svg?style=flat)](https://cocoapods.org/pods/SDWebImagePhotosPlugin)
66
[![Platform](https://img.shields.io/cocoapods/p/SDWebImagePhotosPlugin.svg?style=flat)](https://cocoapods.org/pods/SDWebImagePhotosPlugin)
77
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/SDWebImage/SDWebImagePhotosPlugin)
8+
[![SwiftPM compatible](https://img.shields.io/badge/SwiftPM-Compatible-brightgreen.svg)](https://swift.org/package-manager/)
89
[![codecov](https://codecov.io/gh/SDWebImage/SDWebImagePhotosPlugin/branch/master/graph/badge.svg)](https://codecov.io/gh/SDWebImage/SDWebImagePhotosPlugin)
910

1011
## What's for
@@ -39,6 +40,18 @@ SDWebImagePhotosPlugin is available through [Carthage](https://github.com/Cartha
3940
github "SDWebImage/SDWebImagePhotosPlugin"
4041
```
4142

43+
#### Swift Package Manager
44+
45+
SDWebImagePhotosPlugin is available through [Swift Package Manager](https://swift.org/package-manager).
46+
47+
```swift
48+
let package = Package(
49+
dependencies: [
50+
.package(url: "https://github.com/SDWebImage/SDWebImagePhotosPlugin.git", from: "0.3")
51+
]
52+
)
53+
```
54+
4255
## Usage
4356
**Important!** To use Photos Library plugin. Firstly you need to register the photos loader to image manager.
4457

SDWebImagePhotosPlugin/Classes/PHImageRequestOptions+SDWebImagePhotosPlugin.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#import "PHImageRequestOptions+SDWebImagePhotosPlugin.h"
1010
#import "SDWebImagePhotosDefine.h"
11-
#import <SDWebImage/SDWebImage.h>
1211
#import <objc/runtime.h>
1312

1413
@implementation PHImageRequestOptions (SDWebImagePhotosPlugin)

SDWebImagePhotosPlugin/Classes/SDWebImagePhotosDefine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* file that was distributed with this source code.
77
*/
88

9-
#import <SDWebImage/SDWebImageDefine.h>
9+
@import SDWebImage;
1010

1111
/**
1212
* The scheme when identifing the URL is Photos URL

SDWebImagePhotosPlugin/Classes/SDWebImagePhotosLoader.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
* file that was distributed with this source code.
77
*/
88

9-
#import <SDWebImage/SDWebImage.h>
10-
#import <Photos/Photos.h>
11-
#import "SDWebImagePhotosDefine.h"
9+
@import SDWebImage;
10+
@import Photos;
1211

1312
// The imgae loader to load image asset from Photos library. You need to register the loader into manager firstly. Use `@import SDWebImagePhotosPlugin` to import full framework instead of each header.
1413
// @note To control single image request options, use the context option in `SDWebImagePhotosDefine.h`.

SDWebImagePhotosPlugin/Classes/SDWebImagePhotosLoader.m

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,25 @@
77
*/
88

99
#import "SDWebImagePhotosLoader.h"
10+
#import "SDWebImagePhotosDefine.h"
1011
#import "NSURL+SDWebImagePhotosPlugin.h"
1112
#import "PHImageRequestOptions+SDWebImagePhotosPlugin.h"
1213
#import "SDWebImagePhotosError.h"
1314
#import <objc/runtime.h>
15+
16+
// Compatible
1417
#if SD_UIKIT
1518
#import <MobileCoreServices/MobileCoreServices.h>
1619
typedef UIImageOrientation SDImageOrientation;
1720
#else
1821
typedef CGImagePropertyOrientation SDImageOrientation;
1922
#endif
23+
// This protocol is used to fix the Xcode 11's API declaration for macOS. Which should be available on macOS 10.13
24+
@protocol PHImageManager <NSObject>
25+
- (PHImageRequestID)requestImageDataForAsset:(PHAsset *)asset options:(nullable PHImageRequestOptions *)options resultHandler:(void(^)(NSData *__nullable imageData, NSString *__nullable dataUTI, SDImageOrientation orientation, NSDictionary *__nullable info))resultHandler;
26+
@end
27+
@interface PHImageManager () <PHImageManager>
28+
@end
2029

2130
@interface SDWebImagePhotosLoaderOperation : NSObject <SDWebImageOperation>
2231

@@ -286,7 +295,7 @@ - (void)fetchImageDataWithAsset:(PHAsset *)asset operation:(SDWebImagePhotosLoad
286295
}
287296

288297
__weak typeof(operation) weakOperation = operation;
289-
PHImageRequestID requestID = [[PHImageManager defaultManager] requestImageDataForAsset:asset options:requestOptions resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, SDImageOrientation orientation, NSDictionary * _Nullable info) {
298+
PHImageRequestID requestID = [(id<PHImageManager>)[PHImageManager defaultManager] requestImageDataForAsset:asset options:requestOptions resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, SDImageOrientation orientation, NSDictionary * _Nullable info) {
290299
if (weakOperation.isCancelled) {
291300
// Cancelled
292301
NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled userInfo:nil];

0 commit comments

Comments
 (0)