(receiver, selector, *args, restype, argtypes, varargs=None)
return result
Call a method on the receiver with the given selector and arguments.

    This is the equivalent of an Objective-C method call like ``[receiver sel:args]``.

    .. note::

        Some Objective-C methods take variadic arguments (varargs), for example `+[NSString stringWithFormat:]
        <https://developer.apple.com/documentation/foundation/nsstring/1497275-stringwithformat?language=objc>`_.
        When using :func:`send_message`, variadic arguments are treated differently from regular arguments:
        they are not passed as normal function arguments in ``*args``, but as a list in a separate ``varargs``
        keyword argument.

        This explicit separation of regular and variadic arguments protects against accidentally passing too many
        arguments into a method. By default these extra arguments would be considered varargs and passed on to the
        method, even if the method in question doesn't take varargs. Because of how the Objective-C runtime and most
        C calling conventions work, this error would otherwise be silently ignored.

        The types of varargs are not included in the ``argtypes`` list. Instead, the values are automatically
        converted to C types using the default :mod:`ctypes` argument conversion rules. To ensure that all varargs are
        converted to the expected C types, it is recommended to manually convert all varargs to :mod:`ctypes` types
        instead of relying on automatic conversions. For example:

        .. code-block:: python

            send_message(
                NSString, "stringWithFormat:",
                at("%i %s %@"),
                restype=objc_id, argtypes=[objc_id],
                varargs=[c_int(123), cast(b"C string", c_char_p), at("ObjC string")],
            )

    :param receiver: The object on which to call the method, as an :class:`ObjCInstance` or :class:`objc_id`.
    :param selector: The name of the method as a :class:`str`, :class:`bytes`, or :class:`SEL`.
    :param args: The method arguments.
    :param restype: The return type of the method.
    :param argtypes: The argument types of the method, as a :class:`list`.
    :param varargs: Variadic arguments for the method, as a :class:`list`. Defaults to ``[]``.
        These arguments are converted according to the default :mod:`ctypes` conversion rules.
Call a method on the receiver with the given selector and arguments.
Call a method on the receiver with the given selector and arguments .
def send_message(receiver, selector, *args, restype, argtypes, varargs=None):
    """Call a method on the receiver with the given selector and arguments.

    This is the equivalent of an Objective-C method call like ``[receiver sel:args]``.

    .. note::

        Some Objective-C methods take variadic arguments (varargs), for example `+[NSString stringWithFormat:]
        <https://developer.apple.com/documentation/foundation/nsstring/1497275-stringwithformat?language=objc>`_.
        When using :func:`send_message`, variadic arguments are treated differently from regular arguments:
        they are not passed as normal function arguments in ``*args``, but as a list in a separate ``varargs``
        keyword argument.

        This explicit separation of regular and variadic arguments protects against accidentally passing too many
        arguments into a method. By default these extra arguments would be considered varargs and passed on to the
        method, even if the method in question doesn't take varargs. Because of how the Objective-C runtime and most
        C calling conventions work, this error would otherwise be silently ignored.

        The types of varargs are not included in the ``argtypes`` list. Instead, the values are automatically
        converted to C types using the default :mod:`ctypes` argument conversion rules. To ensure that all varargs are
        converted to the expected C types, it is recommended to manually convert all varargs to :mod:`ctypes` types
        instead of relying on automatic conversions. For example:

        .. code-block:: python

            send_message(
                NSString, "stringWithFormat:",
                at("%i %s %@"),
                restype=objc_id, argtypes=[objc_id],
                varargs=[c_int(123), cast(b"C string", c_char_p), at("ObjC string")],
            )

    :param receiver: The object on which to call the method, as an :class:`ObjCInstance` or :class:`objc_id`.
    :param selector: The name of the method as a :class:`str`, :class:`bytes`, or :class:`SEL`.
    :param args: The method arguments.
    :param restype: The return type of the method.
    :param argtypes: The argument types of the method, as a :class:`list`.
    :param varargs: Variadic arguments for the method, as a :class:`list`. Defaults to ``[]``.
        These arguments are converted according to the default :mod:`ctypes` conversion rules.
    """

    try:
        receiver = receiver._as_parameter_
    except AttributeError:
        pass

    if not isinstance(receiver, objc_id):
        raise TypeError(
            "Receiver must be an ObjCInstance or objc_id, not {tp.__module__}.{tp.__qualname__}"
            .format(tp=type(receiver))
        )

    if not isinstance(selector, SEL):
        selector = SEL(selector)

    if len(args) != len(argtypes):
        raise TypeError(
            "Inconsistent number of arguments ({}) and argument types ({})"
            .format(len(args), len(argtypes))
        )

    if varargs is None:
        varargs = []

    send = _msg_send_for_types(restype, argtypes)

    try:
        result = send(receiver, selector, *args, *varargs)
    except ArgumentError as error:
        # Add more useful info to argument error exceptions, then reraise.
        error.args = (
            error.args[0]
            + ' (selector = {selector}, argtypes = {argtypes})'
            .format(selector=selector, argtypes=argtypes),
        )
        raise

    if restype == c_void_p:
        result = c_void_p(result)
    return result
def send_message ( receiver , selector , * args , restype , argtypes , varargs = None ) : try : receiver = receiver . _as_parameter_ except AttributeError : pass if not isinstance ( receiver , objc_id ) : raise TypeError ( "Receiver must be an ObjCInstance or objc_id, not {tp.__module__}.{tp.__qualname__}" . format ( tp = type ( receiver ) ) ) if not isinstance ( selector , SEL ) : selector = SEL ( selector ) if len ( args ) != len ( argtypes ) : raise TypeError ( "Inconsistent number of arguments ({}) and argument types ({})" . format ( len ( args ) , len ( argtypes ) ) ) if varargs is None : varargs = [ ] send = _msg_send_for_types ( restype , argtypes ) try : result = send ( receiver , selector , * args , * varargs ) except ArgumentError as error : # Add more useful info to argument error exceptions, then reraise. error . args = ( error . args [ 0 ] + ' (selector = {selector}, argtypes = {argtypes})' . format ( selector = selector , argtypes = argtypes ) , ) raise if restype == c_void_p : result = c_void_p ( result ) return result