error: instance method 'methodName' has incompatible result types in different translation units ('methodName' (aka 'NSMutableDictionary *') vs. 'NSMutableDictionary *')
instance method 'methodName' also declared here
(lldb) po self
error: instance method 'operationDictionary' has incompatible result types in different translation units ('SDOperationsDictionary *' (aka 'NSMutableDictionary *') vs. 'NSMutableDictionary *')
instance method 'operationDictionary' also declared here
(lldb)
開(kāi)發(fā)過(guò)程中遇到一個(gè)調(diào)試問(wèn)題。每次po 一個(gè)類及一個(gè)類的方法的時(shí)候總是給出上面的提示廓啊,導(dǎo)致命令不起作用腻贰。但是斷點(diǎn)控制臺(tái)能看到數(shù)據(jù)绑榴。就是LLDB po的時(shí)候出問(wèn)題笼痛。
調(diào)用 image lookup –name methodName
(lldb) image lookup -name operationDictionary
Summary: inke`-[UIView(NTalkerWebCacheOperation) operationDictionary] at UIView+NTalkerWebCacheOperation.m:16 Address: inke[0x000000010156ebc0] (inke.__TEXT.__text + 22446016)
Summary: inke`-[UIView(WebCacheOperation) operationDictionary] at UIView+WebCacheOperation.m:25
(lldb)
看到這個(gè)輸出碰逸,就豁然明白了原因鸟废。是因?yàn)槲覀儗?dǎo)入一個(gè)第三方庫(kù)拾碌,這個(gè)庫(kù)是靜態(tài)庫(kù)(.a庫(kù))雁乡。這個(gè)庫(kù)里面也有一個(gè)UIView的分類叫NTalkerWebCacheOperation第喳,里面有一個(gè)方法叫operationDictionary,但是這個(gè)分類沒(méi)有暴露出來(lái)踱稍,完全是內(nèi)部使用曲饱。然后我們導(dǎo)入了SDWebImage庫(kù)悠抹,這個(gè)庫(kù)里面也有一個(gè)分類
@implementation UIView (WebCacheOperation)
- (SDOperationsDictionary *)operationDictionary {
SDOperationsDictionary *operations = objc_getAssociatedObject(self, &loadOperationKey);
if (operations) {
return operations;
}
operations = [NSMutableDictionary dictionary];
objc_setAssociatedObject(self, &loadOperationKey, operations, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
return operations;
}
這兩個(gè)分類方法重名了。隱藏在.a 靜態(tài)庫(kù)里面扩淀。
在這里介紹一個(gè)LLDB 一個(gè)調(diào)試命令----image lookup
- image lookup –name楔敌,簡(jiǎn)寫(xiě)為image lookup -n。
- 當(dāng)我們想查找一個(gè)方法或者符號(hào)的信息驻谆,比如所在文件位置等卵凑。
- image lookup –name,可以非常有效的定位由于導(dǎo)入某些第三方SDK或者靜態(tài)庫(kù),出現(xiàn)了同名category方法(如果實(shí)現(xiàn)一樣胜臊,此時(shí)問(wèn)題不大勺卢。但是一旦兩個(gè)行為不一致,會(huì)導(dǎo)致一些奇怪的bug)象对。順便說(shuō)下黑忱,如果某個(gè)類多個(gè)擴(kuò)展,有相同方法的勒魔,app在啟動(dòng)的時(shí)候甫煞,會(huì)選擇某個(gè)實(shí)現(xiàn),一旦選擇運(yùn)行的過(guò)程中會(huì)一直都運(yùn)行這個(gè)選擇的實(shí)現(xiàn)冠绢。
感興趣的話產(chǎn)考LLDB調(diào)試技巧