obj_msgSend function pointer crash when build with 64bit arm64

后端 未结 1 392
猫巷女王i
猫巷女王i 2021-02-10 13:05

Actually my original code works great with Xcode 5.0.2 and also great for sending to App Store which is:

objc_msgSend(self.target, self.successAction, category);         


        
1条回答
  •  鱼传尺愫
    2021-02-10 13:38

    Finally, I can reproduce the crash right now. Simply edit Build Scheme and change "Run YOURAPPNAME.app" from Debug to Release.

    And right after I can reproduce this bug, I know how to fix it. Since my selector function type is void(does not return anything), I should not just copy what the question does (using "id").

    By changing:

    id (*response)(id, SEL, id) = (id (*)(id, SEL, id)) objc_msgSend;
    response(self.target, self.successAction, category);
    

    To:

    void (*response)(id, SEL, id) = (void (*)(id, SEL, id)) objc_msgSend;
    response(self.target, self.successAction, category);
    

    It fixes!! Or a one-line code thanks to this commit on github:

    ((void(*)(id, SEL, id))objc_msgSend)(self.target, self.successAction, category);
    

    0 讨论(0)
提交回复
热议问题