iOS 如何快速傳參 ?

游戲或者應(yīng)用開發(fā)的時(shí)候,用觀察者模式有更低的耦合性,開發(fā)速度快,在很多語言平臺(tái)都有廣泛應(yīng)用,這里有介紹:
百度百科傳送門 : https://baike.baidu.com/item/觀察者模式/5881786?fr=aladdin

這里介紹快速創(chuàng)建廣播,傳遞參數(shù),創(chuàng)建偵聽者

創(chuàng)建廣播
#define ncp(ntfname,target,userinfo) do{[[NSNotificationCenter defaultCenter]postNotificationName:ntfname object:target userInfo:(userinfo)];}while(0)
創(chuàng)建偵聽
#define nca(ntfname,target,func) do{[[NSNotificationCenter defaultCenter]addObserver:target selector:@selector(func) name:ntfname object:nil];}while(0)
傳遞參數(shù)
id param = @{@"id":@(_id), @"selected":@(_isSelected)};
ncp(@"ntfVideoSelect", self, param);

id param = @{@"id":@(_id), @"selected":@(_isSelected)};
快速創(chuàng)建字典
@(_id)
快速將數(shù)字/布爾轉(zhuǎn)換為NSNumber
@[@"1",@"2",@"3"]
快速創(chuàng)建數(shù)組

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容