網頁

2021年11月4日 星期四

舊案一直出現 Error: objc_msgSend Calls Too many arguments to function call, expected 0, have 4

 一個很舊的案子去年改過最近重啟加新需求,去年沒事今年卻出現"Too many arguments to function call, expected 0, have 4"的Error,看了看是objc_msgSend這個造成,但看define: "objc_msgSend(id _Nullable self, SEL _Nonnull op, ...)"也看不出來有4個,3個應該也行吧,Google了下Too many arguments to function call, expected 0, have 3中提到https://github.com/th-in-gs/THObserversAndBinders/blob/master/THObserversAndBinders/THObserver.m,根本跟有幾個參數無關,第一個先將"Apple Clang-Preprocessing"中的"Enable Strict Checking of objc_msgSend Calls"改成NO,然後在用到objc_msgSend前面要加參數的型態,如

objc_msgSend(target, action, selectedDate, origin)
改成 => ((void(*)(id, SEL, NSDate*, id))objc_msgSend)(target, action, selectedDate, origin)

這樣就能解決這error了


參考網址:

objc_msgSend()報錯Too many arguments to function call ,expected 0,have2

Too many arguments to function call, expected 0, have 3