SDWebImage原始碼解析

2021-07-24 07:21:11 字數 3080 閱讀 6637

下面從uiimageview的載入開始看起,let's go!

- (void)sd_setimagewithurl:(nsurl *)url placeholderimage:(uiimage *)placeholder;
typedef

ns_options

(nsuinteger, sdwebimageoptions)

;

一般使用的是sdwebimageretryfailed | sdwebimagelowpriority,下面看看具體的函式呼叫:

- (void)sd_setimagewithurl:(nsurl *)url placeholderimage:(uiimage *)placeholder options:(sdwebimageoptions)options progress:(sdwebimage**********progressblock)progressblock completed:(sdwebimagecompletionblock)completedblock 

]; [self sd_setimageloadoperation:operation forkey:@"uiimageviewimageload"];} }

- (id

)downloadimagewithurl:(nsurl *)url options:(sdwebimageoptions)options

progress:(sdwebimage**********progressblock)progressblock

completed:(sdwebimagecompletionwithfinishedblock)completedblock

); }

idsuboperation = [self

.image********** downloadimagewithurl:url options:**********options progress:progressblock completed:^(uiimage *downloadedimage, nsdata *data, nserror *error, bool finished)

dispatch_main_sync_safe(^

});}

}/*...*/

}else

if (image)

});}

}];return operation;

}

- (id

)downloadimagewithurl:(nsurl *)url options:(sdwebimage**********options)options progress:(sdwebimage**********progressblock)progressblock completed:(sdwebimage**********completedblock)completedblock

completed:^(uiimage *image, nsdata *data, nserror *error, bool finished) {}

cancelled:^{}];

operation.shoulddecompressimages = wself.shoulddecompressimages;//是否需要解碼

if (wself.username && wself.password)

if (options & sdwebimage**********highpriority) else

if (options & sdwebimage**********lowpriority)

[wself.downloadqueue addoperation:operation];

if (wself.executionorder == sdwebimage**********lifoexecutionorder)

}];return operation;

}

- (void)start 

}];}

#endif

self

.executing = yes;

self

.connection = [[nsurlconnection alloc] initwithrequest:self

.request delegate:self startimmediately:no];

}[self

.connection start];

if (self

.connection)

//在主線程發通知,這樣也保證在主線程收到通知

dispatch_async(dispatch_get_main_queue(), ^);

cfrunlooprun();//在預設模式下執行當前runlooprun,直到呼叫cfrunloopstop停止執行

if (!self

.isfinished) ]];}}

#if target_os_iphone && __iphone_os_version_max_allowed >= __iphone_4_0

if (self

.backgroundtaskid != uibackgroundtaskinvalid)

#endif

}

- (void)connectiondidfinishloading:(nsurlconnection *)aconnection 

}if (cgsizeequaltosize(image.size, cgsizezero)) ], yes);

}else }}

self

.completionblock = nil;

[self done];

}

後續的快取可以參考:sdwebimage原始碼剖析(二)

SDWebImage的原始碼解讀

sdwebimage共有17個oc檔案以及乙個多餘的標頭檔案,下面將會按照順序乙個乙個進行檔案的解讀 本人學藝不精,如果有不對的地方歡迎指出,有些細節的東西我也不算很理解,寫下這邊也算是方便以後用到的時候回顧 1.imagecontexttype 檔案 主要提供識別資料的格式,是nsdata的分類,...

Fabric 原始碼解析 原始碼目錄解析

這裡對重要的一些目錄進行說明 bccsp 與密碼學 加密 簽名 證書等等 相關的加密服務 將fabric中用到的密碼學相關的函式抽象成了一組介面,便於拓展。bddtests 一種新型的軟體開發模式 行為驅動開 需求 開發 common 一些公共庫 錯誤處理 日誌處理 賬本儲存 策略以及各種工具等等 ...

Spring原始碼解析之 Aop原始碼解析(2)

spring aop 更多的是oop開發模式的乙個補充,幫助oop以更好的方式來解決對於需要解決業務功能模組之上統一管理 的功能 以一副圖來做為aop功能的說明更直觀些。對於類似系統的安全檢查,系統日誌,事務管理等相關功能,物件導向的開發方法並沒有更好的解決方法 aop引入了一些概念。更多的是spr...