码迷,mamicode.com
首页 > Web开发 > 详细

SDWebImage源码阅读(十五)UIView+WebCacheOperation

时间:2017-06-10 20:29:00      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:nat   tom   添加   amp   ima   ide   nil   ret   ring   

  这个分类主要用来对 UIView 的图像下载操作添加、取消和移除。

 .h

1  *  Set the image load operation (storage in a UIView based dictionary)
2  *
3  *  @param operation the operation
4  *  @param key       key for storing the operation
5  */
6 - (void)sd_setImageLoadOperation:(nullable id)operation forKey:(nullable NSString *)key;

  设置图像加载操作。

1 /**
2  *  Cancel all operations for the current UIView and key
3  *
4  *  @param key key for identifying the operations
5  */
6 - (void)sd_cancelImageLoadOperationWithKey:(nullable NSString *)key;

  根据 key 取消 UIView 的所有当前操作。

1 /**
2  *  Just remove the operations corresponding to the current UIView and key without cancelling them
3  *
4  *  @param key key for identifying the operations
5  */
6 - (void)sd_removeImageLoadOperationWithKey:(nullable NSString *)key;

  仅仅根据 key 移除对应的当前 UIView 的操作,并没有取消它们。

 .m

1 static char loadOperationKey;
2 
3 typedef NSMutableDictionary<NSString *, id> SDOperationsDictionary;

  定义一个静态 char loadOperationKey。

  定义一个 key 是字符串 value 是id 的可变字典类型。

1 - (SDOperationsDictionary *)operationDictionary {
2     SDOperationsDictionary *operations = objc_getAssociatedObject(self, &loadOperationKey);
3     if (operations) {
4         return operations;
5     }
6     operations = [NSMutableDictionary dictionary];
7     objc_setAssociatedObject(self, &loadOperationKey, operations, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
8     return operations;
9 }

  给 UIView 动态添加一个 operationDictionary 属性。

 objc_getAssociatedObject

 1 /** 
 2  * Returns the value associated with a given object for a given key.
 3  * 
 4  * @param object The source object for the association.
 5  * @param key The key for the association.
 6  * 
 7  * @return The value associated with the key \e key for \e object.
 8  * 
 9  * @see objc_setAssociatedObject
10  */
11 OBJC_EXPORT id objc_getAssociatedObject(id object, const void *key)
12     OBJC_AVAILABLE(10.6, 3.1, 9.0, 1.0);

 objc_setAssociatedObject

 1 /** 
 2  * Sets an associated value for a given object using a given key and association policy.
 3  * 
 4  * @param object The source object for the association.
 5  * @param key The key for the association.
 6  * @param value The value to associate with the key key for object. Pass nil to clear an existing association.
 7  * @param policy The policy for the association. For possible values, see “Associative Object Behaviors.”
 8  * 
 9  * @see objc_setAssociatedObject
10  * @see objc_removeAssociatedObjects
11  */
12 OBJC_EXPORT void objc_setAssociatedObject(id object, const void *key, id value, objc_AssociationPolicy policy)
13     OBJC_AVAILABLE(10.6, 3.1, 9.0, 1.0);

  

 

SDWebImage源码阅读(十五)UIView+WebCacheOperation

标签:nat   tom   添加   amp   ima   ide   nil   ret   ring   

原文地址:http://www.cnblogs.com/chmhml/p/6979647.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!