Skip to content

Commit 4b2c504

Browse files
committed
Fix the watchOS compile issue, put the associated object and web cache category into a standalone file
1 parent 956be36 commit 4b2c504

File tree

7 files changed

+119
-40
lines changed

7 files changed

+119
-40
lines changed

SDWebImageSwiftUI.xcodeproj/project.pbxproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
324F61CC235E07EC003973B8 /* SDAnimatedImageInterface.m in Sources */ = {isa = PBXBuildFile; fileRef = 324F61C6235E07EC003973B8 /* SDAnimatedImageInterface.m */; };
1616
324F61CD235E07EC003973B8 /* SDAnimatedImageInterface.m in Sources */ = {isa = PBXBuildFile; fileRef = 324F61C6235E07EC003973B8 /* SDAnimatedImageInterface.m */; };
1717
324F61CE235E07EC003973B8 /* SDAnimatedImageInterface.m in Sources */ = {isa = PBXBuildFile; fileRef = 324F61C6235E07EC003973B8 /* SDAnimatedImageInterface.m */; };
18+
3253E05823879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 3253E05623879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.h */; settings = {ATTRIBUTES = (Public, ); }; };
19+
3253E05923879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 3253E05623879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.h */; settings = {ATTRIBUTES = (Public, ); }; };
20+
3253E05A23879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 3253E05623879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.h */; settings = {ATTRIBUTES = (Public, ); }; };
21+
3253E05B23879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 3253E05623879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.h */; settings = {ATTRIBUTES = (Public, ); }; };
22+
3253E05C23879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 3253E05723879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.m */; };
23+
3253E05D23879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 3253E05723879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.m */; };
24+
3253E05E23879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 3253E05723879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.m */; };
25+
3253E05F23879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 3253E05723879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.m */; };
1826
326B84822363350C0011BDFB /* Indicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 326B84812363350C0011BDFB /* Indicator.swift */; };
1927
326B84832363350C0011BDFB /* Indicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 326B84812363350C0011BDFB /* Indicator.swift */; };
2028
326B84842363350C0011BDFB /* Indicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 326B84812363350C0011BDFB /* Indicator.swift */; };
@@ -123,6 +131,8 @@
123131
/* Begin PBXFileReference section */
124132
324F61C5235E07EC003973B8 /* SDAnimatedImageInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDAnimatedImageInterface.h; sourceTree = "<group>"; };
125133
324F61C6235E07EC003973B8 /* SDAnimatedImageInterface.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDAnimatedImageInterface.m; sourceTree = "<group>"; };
134+
3253E05623879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SDAnimatedImageInterface+WebCache.h"; sourceTree = "<group>"; };
135+
3253E05723879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "SDAnimatedImageInterface+WebCache.m"; sourceTree = "<group>"; };
126136
326B84812363350C0011BDFB /* Indicator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Indicator.swift; sourceTree = "<group>"; };
127137
326B8486236335110011BDFB /* ActivityIndicator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActivityIndicator.swift; sourceTree = "<group>"; };
128138
326B848B236335400011BDFB /* ProgressIndicator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProgressIndicator.swift; sourceTree = "<group>"; };
@@ -187,6 +197,8 @@
187197
children = (
188198
324F61C5235E07EC003973B8 /* SDAnimatedImageInterface.h */,
189199
324F61C6235E07EC003973B8 /* SDAnimatedImageInterface.m */,
200+
3253E05623879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.h */,
201+
3253E05723879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.m */,
190202
3276EAFE237760D800B385D4 /* SDAnimatedImageInterfaceWrapper.h */,
191203
3276EAFF237760D800B385D4 /* SDAnimatedImageInterfaceWrapper.m */,
192204
);
@@ -274,6 +286,7 @@
274286
isa = PBXHeadersBuildPhase;
275287
buildActionMask = 2147483647;
276288
files = (
289+
3253E05823879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.h in Headers */,
277290
3276EB00237760D800B385D4 /* SDAnimatedImageInterfaceWrapper.h in Headers */,
278291
324F61C7235E07EC003973B8 /* SDAnimatedImageInterface.h in Headers */,
279292
32C43DE622FD54CD00BE87F5 /* SDWebImageSwiftUI.h in Headers */,
@@ -284,6 +297,7 @@
284297
isa = PBXHeadersBuildPhase;
285298
buildActionMask = 2147483647;
286299
files = (
300+
3253E05923879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.h in Headers */,
287301
3276EB01237760D800B385D4 /* SDAnimatedImageInterfaceWrapper.h in Headers */,
288302
324F61C8235E07EC003973B8 /* SDAnimatedImageInterface.h in Headers */,
289303
32C43E2222FD583A00BE87F5 /* SDWebImageSwiftUI.h in Headers */,
@@ -294,6 +308,7 @@
294308
isa = PBXHeadersBuildPhase;
295309
buildActionMask = 2147483647;
296310
files = (
311+
3253E05A23879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.h in Headers */,
297312
3276EB02237760D800B385D4 /* SDAnimatedImageInterfaceWrapper.h in Headers */,
298313
324F61C9235E07EC003973B8 /* SDAnimatedImageInterface.h in Headers */,
299314
32C43E2322FD583B00BE87F5 /* SDWebImageSwiftUI.h in Headers */,
@@ -304,6 +319,7 @@
304319
isa = PBXHeadersBuildPhase;
305320
buildActionMask = 2147483647;
306321
files = (
322+
3253E05B23879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.h in Headers */,
307323
3276EB03237760D800B385D4 /* SDAnimatedImageInterfaceWrapper.h in Headers */,
308324
324F61CA235E07EC003973B8 /* SDAnimatedImageInterface.h in Headers */,
309325
32C43E2422FD583C00BE87F5 /* SDWebImageSwiftUI.h in Headers */,
@@ -482,6 +498,7 @@
482498
326E480A23431C0F00C633E9 /* ImageViewWrapper.swift in Sources */,
483499
326B8487236335110011BDFB /* ActivityIndicator.swift in Sources */,
484500
32C43E1622FD583700BE87F5 /* ImageManager.swift in Sources */,
501+
3253E05C23879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.m in Sources */,
485502
32C43E1822FD583700BE87F5 /* AnimatedImage.swift in Sources */,
486503
324F61CB235E07EC003973B8 /* SDAnimatedImageInterface.m in Sources */,
487504
);
@@ -500,6 +517,7 @@
500517
326E480B23431C0F00C633E9 /* ImageViewWrapper.swift in Sources */,
501518
326B8488236335110011BDFB /* ActivityIndicator.swift in Sources */,
502519
32C43E1922FD583700BE87F5 /* ImageManager.swift in Sources */,
520+
3253E05D23879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.m in Sources */,
503521
32C43E1B22FD583700BE87F5 /* AnimatedImage.swift in Sources */,
504522
324F61CC235E07EC003973B8 /* SDAnimatedImageInterface.m in Sources */,
505523
);
@@ -518,6 +536,7 @@
518536
326E480C23431C0F00C633E9 /* ImageViewWrapper.swift in Sources */,
519537
326B8489236335110011BDFB /* ActivityIndicator.swift in Sources */,
520538
32C43E1C22FD583800BE87F5 /* ImageManager.swift in Sources */,
539+
3253E05E23879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.m in Sources */,
521540
32C43E1E22FD583800BE87F5 /* AnimatedImage.swift in Sources */,
522541
324F61CD235E07EC003973B8 /* SDAnimatedImageInterface.m in Sources */,
523542
);
@@ -536,6 +555,7 @@
536555
326E480D23431C0F00C633E9 /* ImageViewWrapper.swift in Sources */,
537556
326B848A236335110011BDFB /* ActivityIndicator.swift in Sources */,
538557
32C43E1F22FD583800BE87F5 /* ImageManager.swift in Sources */,
558+
3253E05F23879A6F007ACAD8 /* SDAnimatedImageInterface+WebCache.m in Sources */,
539559
32C43E2122FD583800BE87F5 /* AnimatedImage.swift in Sources */,
540560
324F61CE235E07EC003973B8 /* SDAnimatedImageInterface.m in Sources */,
541561
);

SDWebImageSwiftUI/Classes/AnimatedImage.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,19 @@ public struct AnimatedImage : PlatformViewRepresentable {
231231
let image = SDAnimatedImage(named: name, in: imageModel.bundle, compatibleWith: nil)
232232
#endif
233233
view.wrapped.sd_imageName = name
234+
#if os(iOS) || os(tvOS) || os(macOS)
234235
view.wrapped.image = image
236+
#else
237+
view.wrapped.setImage(image)
238+
#endif
235239
} else if let data = imageModel.data, data != view.wrapped.sd_imageData {
236240
let image = SDAnimatedImage(data: data, scale: imageModel.scale)
237241
view.wrapped.sd_imageData = data
242+
#if os(iOS) || os(tvOS) || os(macOS)
238243
view.wrapped.image = image
244+
#else
245+
view.wrapped.setImage(image)
246+
#endif
239247
} else if let url = imageModel.url, url != view.wrapped.sd_imageURL {
240248
#if os(macOS) || os(iOS) || os(tvOS)
241249
view.wrapped.sd_imageIndicator = imageConfiguration.indicator
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* This file is part of the SDWebImage package.
3+
* (c) DreamPiggy <[email protected]>
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*/
8+
9+
#import "SDAnimatedImageInterface.h"
10+
11+
#if SD_WATCH
12+
NS_ASSUME_NONNULL_BEGIN
13+
14+
/// Do not use this class directly in WatchKit or Storyboard. This class is implementation detail and will be removed in the future.
15+
/// This is not public API at all.
16+
@interface SDAnimatedImageInterface (WebCache)
17+
18+
@property (nonatomic, strong, nullable) NSString *sd_imageName;
19+
@property (nonatomic, strong, nullable) NSData *sd_imageData;
20+
21+
- (void)sd_setImageWithURL:(nullable NSURL *)url
22+
placeholderImage:(nullable UIImage *)placeholder
23+
options:(SDWebImageOptions)options
24+
context:(nullable SDWebImageContext *)context
25+
progress:(nullable SDImageLoaderProgressBlock)progressBlock
26+
completed:(nullable SDExternalCompletionBlock)completedBlock;
27+
28+
@end
29+
30+
NS_ASSUME_NONNULL_END
31+
#endif
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* This file is part of the SDWebImage package.
3+
* (c) DreamPiggy <[email protected]>
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*/
8+
9+
#import "SDAnimatedImageInterface+WebCache.h"
10+
#import <objc/runtime.h>
11+
12+
@implementation SDAnimatedImageInterface (WebCache)
13+
14+
- (NSString *)sd_imageName {
15+
return objc_getAssociatedObject(self, @selector(sd_imageName));
16+
}
17+
18+
- (void)setSd_imageName:(NSString *)sd_imageName {
19+
objc_setAssociatedObject(self, @selector(sd_imageName), sd_imageName, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
20+
}
21+
22+
- (NSData *)sd_imageData {
23+
return objc_getAssociatedObject(self, @selector(sd_imageData));
24+
}
25+
26+
- (void)setSd_imageData:(NSData *)sd_imageData {
27+
objc_setAssociatedObject(self, @selector(sd_imageData), sd_imageData, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
28+
}
29+
30+
- (void)sd_setImageWithURL:(nullable NSURL *)url
31+
placeholderImage:(nullable UIImage *)placeholder
32+
options:(SDWebImageOptions)options
33+
context:(nullable SDWebImageContext *)context
34+
progress:(nullable SDImageLoaderProgressBlock)progressBlock
35+
completed:(nullable SDExternalCompletionBlock)completedBlock {
36+
Class animatedImageClass = [SDAnimatedImage class];
37+
SDWebImageMutableContext *mutableContext;
38+
if (context) {
39+
mutableContext = [context mutableCopy];
40+
} else {
41+
mutableContext = [NSMutableDictionary dictionary];
42+
}
43+
mutableContext[SDWebImageContextAnimatedImageClass] = animatedImageClass;
44+
[self sd_internalSetImageWithURL:url
45+
placeholderImage:placeholder
46+
options:options
47+
context:mutableContext
48+
setImageBlock:nil
49+
progress:progressBlock
50+
completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
51+
if (completedBlock) {
52+
completedBlock(image, error, cacheType, imageURL);
53+
}
54+
}];
55+
}
56+
57+
@end

SDWebImageSwiftUI/Classes/ObjC/SDAnimatedImageInterface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
1515
/// This is not public API at all.
1616
@interface SDAnimatedImageInterface : WKInterfaceImage
1717

18+
@property (nonatomic, strong, readonly, nullable) UIImage *image;
1819
@property (nonatomic, assign, getter=isAnimating, readonly) BOOL animating;
1920
@property (nonatomic, assign) SDImageScaleMode contentMode;
2021
@property (nonatomic, strong, nullable) NSNumber *animationRepeatCount;

SDWebImageSwiftUI/Classes/ObjC/SDAnimatedImageInterface.m

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ - (NSDictionary *)interfaceDescriptionForDynamicCreation;
5757

5858
@end
5959

60-
@interface SDAnimatedImageInterface () {
61-
UIImage *_image;
62-
}
60+
@interface SDAnimatedImageInterface ()
6361

6462
@property (nonatomic, strong, readwrite) UIImage *currentFrame;
6563
@property (nonatomic, assign, readwrite) NSUInteger currentFrameIndex;
@@ -213,41 +211,4 @@ - (SDImageScaleMode)contentMode {
213211

214212
@end
215213

216-
#pragma mark - Web Cache
217-
218-
@interface SDAnimatedImageInterface (WebCache)
219-
220-
@end
221-
222-
@implementation SDAnimatedImageInterface (WebCache)
223-
224-
- (void)sd_setImageWithURL:(nullable NSURL *)url
225-
placeholderImage:(nullable UIImage *)placeholder
226-
options:(SDWebImageOptions)options
227-
context:(nullable SDWebImageContext *)context
228-
progress:(nullable SDImageLoaderProgressBlock)progressBlock
229-
completed:(nullable SDExternalCompletionBlock)completedBlock {
230-
Class animatedImageClass = [SDAnimatedImage class];
231-
SDWebImageMutableContext *mutableContext;
232-
if (context) {
233-
mutableContext = [context mutableCopy];
234-
} else {
235-
mutableContext = [NSMutableDictionary dictionary];
236-
}
237-
mutableContext[SDWebImageContextAnimatedImageClass] = animatedImageClass;
238-
[self sd_internalSetImageWithURL:url
239-
placeholderImage:placeholder
240-
options:options
241-
context:mutableContext
242-
setImageBlock:nil
243-
progress:progressBlock
244-
completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
245-
if (completedBlock) {
246-
completedBlock(image, error, cacheType, imageURL);
247-
}
248-
}];
249-
}
250-
251-
@end
252-
253214
#endif

SDWebImageSwiftUI/Module/SDWebImageSwiftUI.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ FOUNDATION_EXPORT const unsigned char SDWebImageSwiftUIVersionString[];
1616

1717
// In this header, you should import all the public headers of your framework using statements like #import <SDWebImageSwiftUI/PublicHeader.h>
1818
#import <SDWebImageSwiftUI/SDAnimatedImageInterface.h>
19+
#import <SDWebImageSwiftUI/SDAnimatedImageInterface+WebCache.h>
1920
#import <SDWebImageSwiftUI/SDAnimatedImageInterfaceWrapper.h>

0 commit comments

Comments
 (0)