SDWebImage源碼閱讀(十五)UIView+WebCacheOperation

來源:互聯網
上載者:User

標籤: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 operation4  *  @param key       key for storing the operation5  */6 - (void)sd_setImageLoadOperation:(nullable id)operation forKey:(nullable NSString *)key;

  設定映像載入操作。

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

  根據 key 取消 UIView 的所有當前操作。

1 /**2  *  Just remove the operations corresponding to the current UIView and key without cancelling them3  *4  *  @param key key for identifying the operations5  */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_setAssociatedObject10  */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_setAssociatedObject10  * @see objc_removeAssociatedObjects11  */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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.