Fix CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF warning
Showing
1 changed file
with
16 additions
and
17 deletions
@@ -26,13 +26,12 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | @@ -26,13 +26,12 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | ||
26 | @property (strong, nonatomic, nonnull) NSString *diskCachePath; | 26 | @property (strong, nonatomic, nonnull) NSString *diskCachePath; |
27 | @property (strong, nonatomic, nullable) NSMutableArray<NSString *> *customPaths; | 27 | @property (strong, nonatomic, nullable) NSMutableArray<NSString *> *customPaths; |
28 | @property (strong, nonatomic, nullable) dispatch_queue_t ioQueue; | 28 | @property (strong, nonatomic, nullable) dispatch_queue_t ioQueue; |
29 | +@property (strong, nonatomic, nonnull) NSFileManager *fileManager; | ||
29 | 30 | ||
30 | @end | 31 | @end |
31 | 32 | ||
32 | 33 | ||
33 | -@implementation SDImageCache { | ||
34 | - NSFileManager *_fileManager; | ||
35 | -} | 34 | +@implementation SDImageCache |
36 | 35 | ||
37 | #pragma mark - Singleton, init, dealloc | 36 | #pragma mark - Singleton, init, dealloc |
38 | 37 | ||
@@ -224,8 +223,8 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | @@ -224,8 +223,8 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | ||
224 | return; | 223 | return; |
225 | } | 224 | } |
226 | 225 | ||
227 | - if (![_fileManager fileExistsAtPath:_diskCachePath]) { | ||
228 | - [_fileManager createDirectoryAtPath:_diskCachePath withIntermediateDirectories:YES attributes:nil error:NULL]; | 226 | + if (![self.fileManager fileExistsAtPath:_diskCachePath]) { |
227 | + [self.fileManager createDirectoryAtPath:_diskCachePath withIntermediateDirectories:YES attributes:nil error:NULL]; | ||
229 | } | 228 | } |
230 | 229 | ||
231 | // get cache Path for image key | 230 | // get cache Path for image key |
@@ -271,12 +270,12 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | @@ -271,12 +270,12 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | ||
271 | if (!key) { | 270 | if (!key) { |
272 | return NO; | 271 | return NO; |
273 | } | 272 | } |
274 | - BOOL exists = [_fileManager fileExistsAtPath:[self defaultCachePathForKey:key]]; | 273 | + BOOL exists = [self.fileManager fileExistsAtPath:[self defaultCachePathForKey:key]]; |
275 | 274 | ||
276 | // fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name | 275 | // fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name |
277 | // checking the key with and without the extension | 276 | // checking the key with and without the extension |
278 | if (!exists) { | 277 | if (!exists) { |
279 | - exists = [_fileManager fileExistsAtPath:[self defaultCachePathForKey:key].stringByDeletingPathExtension]; | 278 | + exists = [self.fileManager fileExistsAtPath:[self defaultCachePathForKey:key].stringByDeletingPathExtension]; |
280 | } | 279 | } |
281 | 280 | ||
282 | return exists; | 281 | return exists; |
@@ -447,7 +446,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | @@ -447,7 +446,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | ||
447 | 446 | ||
448 | if (fromDisk) { | 447 | if (fromDisk) { |
449 | dispatch_async(self.ioQueue, ^{ | 448 | dispatch_async(self.ioQueue, ^{ |
450 | - [_fileManager removeItemAtPath:[self defaultCachePathForKey:key] error:nil]; | 449 | + [self.fileManager removeItemAtPath:[self defaultCachePathForKey:key] error:nil]; |
451 | 450 | ||
452 | if (completion) { | 451 | if (completion) { |
453 | dispatch_async(dispatch_get_main_queue(), ^{ | 452 | dispatch_async(dispatch_get_main_queue(), ^{ |
@@ -487,8 +486,8 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | @@ -487,8 +486,8 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | ||
487 | 486 | ||
488 | - (void)clearDiskOnCompletion:(nullable SDWebImageNoParamsBlock)completion { | 487 | - (void)clearDiskOnCompletion:(nullable SDWebImageNoParamsBlock)completion { |
489 | dispatch_async(self.ioQueue, ^{ | 488 | dispatch_async(self.ioQueue, ^{ |
490 | - [_fileManager removeItemAtPath:self.diskCachePath error:nil]; | ||
491 | - [_fileManager createDirectoryAtPath:self.diskCachePath | 489 | + [self.fileManager removeItemAtPath:self.diskCachePath error:nil]; |
490 | + [self.fileManager createDirectoryAtPath:self.diskCachePath | ||
492 | withIntermediateDirectories:YES | 491 | withIntermediateDirectories:YES |
493 | attributes:nil | 492 | attributes:nil |
494 | error:NULL]; | 493 | error:NULL]; |
@@ -511,7 +510,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | @@ -511,7 +510,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | ||
511 | NSArray<NSString *> *resourceKeys = @[NSURLIsDirectoryKey, NSURLContentModificationDateKey, NSURLTotalFileAllocatedSizeKey]; | 510 | NSArray<NSString *> *resourceKeys = @[NSURLIsDirectoryKey, NSURLContentModificationDateKey, NSURLTotalFileAllocatedSizeKey]; |
512 | 511 | ||
513 | // This enumerator prefetches useful properties for our cache files. | 512 | // This enumerator prefetches useful properties for our cache files. |
514 | - NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtURL:diskCacheURL | 513 | + NSDirectoryEnumerator *fileEnumerator = [self.fileManager enumeratorAtURL:diskCacheURL |
515 | includingPropertiesForKeys:resourceKeys | 514 | includingPropertiesForKeys:resourceKeys |
516 | options:NSDirectoryEnumerationSkipsHiddenFiles | 515 | options:NSDirectoryEnumerationSkipsHiddenFiles |
517 | errorHandler:NULL]; | 516 | errorHandler:NULL]; |
@@ -548,7 +547,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | @@ -548,7 +547,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | ||
548 | } | 547 | } |
549 | 548 | ||
550 | for (NSURL *fileURL in urlsToDelete) { | 549 | for (NSURL *fileURL in urlsToDelete) { |
551 | - [_fileManager removeItemAtURL:fileURL error:nil]; | 550 | + [self.fileManager removeItemAtURL:fileURL error:nil]; |
552 | } | 551 | } |
553 | 552 | ||
554 | // If our remaining disk cache exceeds a configured maximum size, perform a second | 553 | // If our remaining disk cache exceeds a configured maximum size, perform a second |
@@ -565,7 +564,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | @@ -565,7 +564,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | ||
565 | 564 | ||
566 | // Delete files until we fall below our desired cache size. | 565 | // Delete files until we fall below our desired cache size. |
567 | for (NSURL *fileURL in sortedFiles) { | 566 | for (NSURL *fileURL in sortedFiles) { |
568 | - if ([_fileManager removeItemAtURL:fileURL error:nil]) { | 567 | + if ([self.fileManager removeItemAtURL:fileURL error:nil]) { |
569 | NSDictionary<NSString *, id> *resourceValues = cacheFiles[fileURL]; | 568 | NSDictionary<NSString *, id> *resourceValues = cacheFiles[fileURL]; |
570 | NSNumber *totalAllocatedSize = resourceValues[NSURLTotalFileAllocatedSizeKey]; | 569 | NSNumber *totalAllocatedSize = resourceValues[NSURLTotalFileAllocatedSizeKey]; |
571 | currentCacheSize -= totalAllocatedSize.unsignedIntegerValue; | 570 | currentCacheSize -= totalAllocatedSize.unsignedIntegerValue; |
@@ -611,10 +610,10 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | @@ -611,10 +610,10 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | ||
611 | - (NSUInteger)getSize { | 610 | - (NSUInteger)getSize { |
612 | __block NSUInteger size = 0; | 611 | __block NSUInteger size = 0; |
613 | dispatch_sync(self.ioQueue, ^{ | 612 | dispatch_sync(self.ioQueue, ^{ |
614 | - NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtPath:self.diskCachePath]; | 613 | + NSDirectoryEnumerator *fileEnumerator = [self.fileManager enumeratorAtPath:self.diskCachePath]; |
615 | for (NSString *fileName in fileEnumerator) { | 614 | for (NSString *fileName in fileEnumerator) { |
616 | NSString *filePath = [self.diskCachePath stringByAppendingPathComponent:fileName]; | 615 | NSString *filePath = [self.diskCachePath stringByAppendingPathComponent:fileName]; |
617 | - NSDictionary<NSString *, id> *attrs = [_fileManager attributesOfItemAtPath:filePath error:nil]; | 616 | + NSDictionary<NSString *, id> *attrs = [self.fileManager attributesOfItemAtPath:filePath error:nil]; |
618 | size += [attrs fileSize]; | 617 | size += [attrs fileSize]; |
619 | } | 618 | } |
620 | }); | 619 | }); |
@@ -624,7 +623,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | @@ -624,7 +623,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | ||
624 | - (NSUInteger)getDiskCount { | 623 | - (NSUInteger)getDiskCount { |
625 | __block NSUInteger count = 0; | 624 | __block NSUInteger count = 0; |
626 | dispatch_sync(self.ioQueue, ^{ | 625 | dispatch_sync(self.ioQueue, ^{ |
627 | - NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtPath:self.diskCachePath]; | 626 | + NSDirectoryEnumerator *fileEnumerator = [self.fileManager enumeratorAtPath:self.diskCachePath]; |
628 | count = fileEnumerator.allObjects.count; | 627 | count = fileEnumerator.allObjects.count; |
629 | }); | 628 | }); |
630 | return count; | 629 | return count; |
@@ -637,7 +636,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | @@ -637,7 +636,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | ||
637 | NSUInteger fileCount = 0; | 636 | NSUInteger fileCount = 0; |
638 | NSUInteger totalSize = 0; | 637 | NSUInteger totalSize = 0; |
639 | 638 | ||
640 | - NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtURL:diskCacheURL | 639 | + NSDirectoryEnumerator *fileEnumerator = [self.fileManager enumeratorAtURL:diskCacheURL |
641 | includingPropertiesForKeys:@[NSFileSize] | 640 | includingPropertiesForKeys:@[NSFileSize] |
642 | options:NSDirectoryEnumerationSkipsHiddenFiles | 641 | options:NSDirectoryEnumerationSkipsHiddenFiles |
643 | errorHandler:NULL]; | 642 | errorHandler:NULL]; |
-
Please register or login to post a comment