Proper place for the pragma mark and used a function to check for the proper queue
Showing
1 changed file
with
9 additions
and
5 deletions
@@ -136,6 +136,12 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | @@ -136,6 +136,12 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | ||
136 | SDDispatchQueueRelease(_ioQueue); | 136 | SDDispatchQueueRelease(_ioQueue); |
137 | } | 137 | } |
138 | 138 | ||
139 | +- (void)checkIfQueueIsIOQueue { | ||
140 | + const char *currentQueueLabel = dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL); | ||
141 | + const char *ioQueueLabel = dispatch_queue_get_label(self.ioQueue); | ||
142 | + NSAssert(strcmp(currentQueueLabel, ioQueueLabel) == 0, @"This method should be called from the ioQueue"); | ||
143 | +} | ||
144 | + | ||
139 | #pragma mark - Cache paths | 145 | #pragma mark - Cache paths |
140 | 146 | ||
141 | - (void)addReadOnlyCachePath:(nonnull NSString *)path { | 147 | - (void)addReadOnlyCachePath:(nonnull NSString *)path { |
@@ -236,9 +242,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | @@ -236,9 +242,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | ||
236 | return; | 242 | return; |
237 | } | 243 | } |
238 | 244 | ||
239 | - const char *currentQueueLabel = dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL); | ||
240 | - const char *ioQueueLabel = dispatch_queue_get_label(self.ioQueue); | ||
241 | - NSAssert(strcmp(currentQueueLabel, ioQueueLabel) == 0, @"This method should be called from the ioQueue"); | 245 | + [self checkIfQueueIsIOQueue]; |
242 | 246 | ||
243 | if (![_fileManager fileExistsAtPath:_diskCachePath]) { | 247 | if (![_fileManager fileExistsAtPath:_diskCachePath]) { |
244 | [_fileManager createDirectoryAtPath:_diskCachePath withIntermediateDirectories:YES attributes:nil error:NULL]; | 248 | [_fileManager createDirectoryAtPath:_diskCachePath withIntermediateDirectories:YES attributes:nil error:NULL]; |
@@ -257,6 +261,8 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | @@ -257,6 +261,8 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | ||
257 | } | 261 | } |
258 | } | 262 | } |
259 | 263 | ||
264 | +#pragma mark - Query and Retrieve Ops | ||
265 | + | ||
260 | - (void)diskImageExistsWithKey:(nullable NSString *)key completion:(nullable SDWebImageCheckCacheCompletionBlock)completionBlock { | 266 | - (void)diskImageExistsWithKey:(nullable NSString *)key completion:(nullable SDWebImageCheckCacheCompletionBlock)completionBlock { |
261 | dispatch_async(_ioQueue, ^{ | 267 | dispatch_async(_ioQueue, ^{ |
262 | BOOL exists = [_fileManager fileExistsAtPath:[self defaultCachePathForKey:key]]; | 268 | BOOL exists = [_fileManager fileExistsAtPath:[self defaultCachePathForKey:key]]; |
@@ -275,8 +281,6 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | @@ -275,8 +281,6 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | ||
275 | }); | 281 | }); |
276 | } | 282 | } |
277 | 283 | ||
278 | -#pragma mark - Query and Retrieve Ops | ||
279 | - | ||
280 | - (nullable UIImage *)imageFromMemoryCacheForKey:(nullable NSString *)key { | 284 | - (nullable UIImage *)imageFromMemoryCacheForKey:(nullable NSString *)key { |
281 | return [self.memCache objectForKey:key]; | 285 | return [self.memCache objectForKey:key]; |
282 | } | 286 | } |
-
Please register or login to post a comment