В xcode6 gold master, используя objc_msgSend, теперь выдает синтаксическую ошибку, в которой указано количество аргументов

 id<MyProtocol> topLayoutGuideObj = objc_msgSend(viewController, @selector(myselector));

"Слишком много аргументов для вызова функции, ожидаемого 0, имеют 2"

Однако подпись функции для objc_msgSend выглядит следующим образом:

#if !OBJC_OLD_DISPATCH_PROTOTYPES
OBJC_EXPORT void objc_msgSend(void /* id self, SEL op, ... */ )
    __OSX_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);
OBJC_EXPORT void objc_msgSendSuper(void /* struct objc_super *super, SEL op, ... */ )
    __OSX_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);
#else
/** 
 * Sends a message with a simple return value to an instance of a class.
 * 
 * @param self A pointer to the instance of the class that is to receive the message.
 * @param op The selector of the method that handles the message.
 * @param ... 
 *   A variable argument list containing the arguments to the method.
 * 
 * @return The return value of the method.
 * 
 * @note When it encounters a method call, the compiler generates a call to one of the
 *  functions \c objc_msgSend, \c objc_msgSend_stret, \c objc_msgSendSuper, or \c objc_msgSendSuper_stret.
 *  Messages sent to an object’s superclass (using the \c super keyword) are sent using \c objc_msgSendSuper; 
 *  other messages are sent using \c objc_msgSend. Methods that have data structures as return values
 *  are sent using \c objc_msgSendSuper_stret and \c objc_msgSend_stret.
 */
OBJC_EXPORT id objc_msgSend(id self, SEL op, ...)
    __OSX_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);

Аргументы являются "пустыми" или переменными?! Я не понимаю, как я должен это назвать.

Ответы

Ответ 1

Посмотрите на несколько строк выше, чем вы указали.

 /* 
  * ...
  *
  * These functions must be cast to an appropriate function pointer type 
  * before being called. 
  */

Вы можете называть его так:

#import <objc/runtime.h>
#import <objc/message.h>

id<MyProtocol> topLayoutGuideObj = ((id (*)(id, SEL))objc_msgSend)(viewController, @selector(myselector));

ИЛИ

id (*typed_msgSend)(id, SEL) = (void *)objc_msgSend;
id<MyProtocol> topLayoutGuideObj = typed_msgSend(viewController, @selector(myselector));

Ответ 2

Я проверил это, основная проблема заключалась в том, что @Jerry Krinock сказал в комментарии к принятому ответу;

  • Перейдите в свой проект Настройки сборки
  • Поиск objc_msgSend
  • Установите значение "Нет" вместо "Да"

Ответ 3

если это происходит в libc cocoapod, вам просто нужно обновить по крайней мере до коко файлов 36.1. Если вы не можете сделать это, добавьте следующий код в конец вашего подкадрового файла:

(замените AFNetworking на модуль, где вы видите эти ошибки)

when /AFNetworking/            
    target.build_configurations.each do |config|
        config.build_settings['ENABLE_STRICT_OBJC_MSGSEND'] = "NO"
end