這期內(nèi)容當(dāng)中小編將會給大家?guī)碛嘘P(guān)Method Swizzling對Method的要求是什么,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
通過method_exchangeImplementation、class_replaceMethod、method_setImplementation進(jìn)行Method Swizzling時(shí),對originalMethod和destMethod的要求如下:
(1)返回值類型可以不同。如:
- (void)func1:(NSString *)word{ NSLog(@"This is func1~"); } - (BOOL)func2:(NSString *)word{ NSLog(@"This is func2~"); return YES; }
(2)參數(shù)個(gè)數(shù)可以不同。如:
- (void)func1:(NSString *)word{ NSLog(@"This is func1~"); } - (void)func2:(NSString *)word sec:(NSString *)word2{ NSLog(@"This is func2~"); }
(3)但是!對應(yīng)參數(shù)類型必須相同??!如:
- (void)func1:(NSString *)word{ NSLog(@"This is func1~"); } - (void)func2:(NSString *)word sec:(NSString *)word2{ NSLog(@"This is func2~"); }
第一個(gè)參數(shù)都為NSString類型。
- (void)func1:(NSString *)word sec:(int)word2 third:(BOOL)word3{ NSLog(@"This is func1~"); } - (void)func2:(NSString *)word sec:(int)word2 { NSLog(@"This is func2~"); }
func1第一個(gè)參數(shù)為NSString,func2第一個(gè)參數(shù)也為NSString;func1第二參數(shù)為int,func2第二個(gè)參數(shù)也為int。
- (void)func1:(NSString *)word sec:(int)word2 third:(BOOL)word3{ NSLog(@"This is func1~"); } - (void)func2:(NSString *)word sec:(int)word2 third:(NSString *)word3 { NSLog(@"This is func2~"); }
上面的情況則會報(bào)錯(cuò)!
上述就是小編為大家分享的Method Swizzling對Method的要求是什么了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)網(wǎng)站制作公司行業(yè)資訊頻道。
創(chuàng)新互聯(lián)www.cdcxhl.cn,專業(yè)提供香港、美國云服務(wù)器,動(dòng)態(tài)BGP最優(yōu)骨干路由自動(dòng)選擇,持續(xù)穩(wěn)定高效的網(wǎng)絡(luò)助力業(yè)務(wù)部署。公司持有工信部辦法的idc、isp許可證, 機(jī)房獨(dú)有T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確進(jìn)行流量調(diào)度,確保服務(wù)器高可用性。佳節(jié)活動(dòng)現(xiàn)已開啟,新人活動(dòng)云服務(wù)器買多久送多久。