我知道我可以調用一個類的方法一樣[MyClass myMethod];
做[NSClassFromString(@"MyClass") performSelector:@selector(myMethod)];
iOS的Objective-C的 - 調用類方法在類動態創建了NSClassFromString
我目前正試圖但是要做到這一點:
[MyClass configureWithNum:@"12345"
andNumber:@"2312312"
options:nil
completion:^(NSArray<SecondClass*>* array) {}
];
當我這樣做:
[NSClassFromString(@"MyClass") performSelector:@selector(configureWithNum)
withObject:@"12345"
withObject:@"2312312"
withObject:nil
withObject:^(NSArray<SecondClass*>* array) {}];
它拋出一個Undeclared selection 'configureWithNum'
。
看起來好像performSelector withObject調用只適用於一個參數。所以我懷疑我需要採用this這樣的做法,使用objc_msgSend
,但我似乎無法獲得正確的格式。
我覺得this SO是沿着正確的軌道 - 但我似乎無法得到它的權利。當我這樣做:
objc_msgSend(NSClassFromString(@"MyClass"), sel_getUid("configureWithNum:andNumber:options:completion:"), @"12345", @"2312312", nil, ^(NSArray<AdColonyZone*>* zones) {});
它給我一個implicit declaration of function 'objc_msgSend' is invalid in C99
錯誤。
任何想法如何使用無論是objc_msgSend
或performSelector: withObject:
實現這個電話嗎?
所以對於這一個,我不需要明確地調出參數名稱,我可以只是通過參數或多或少? –