(obj, varname, value, weak=False)
Set obj's ivar varname to value. If ``weak`` is ``True``, only a weak reference to the value is stored.

    value must be a :mod:`ctypes` data object whose type matches that of the ivar.
Set obj's ivar varname to value. If ``weak`` is ``True``, only a weak reference to the value is stored.
Set obj s ivar varname to value . If weak is True only a weak reference to the value is stored .
def set_ivar(obj, varname, value, weak=False):
    """Set obj's ivar varname to value. If ``weak`` is ``True``, only a weak reference to the value is stored.

    value must be a :mod:`ctypes` data object whose type matches that of the ivar.
    """

    try:
        obj = obj._as_parameter_
    except AttributeError:
        pass

    ivar = libobjc.class_getInstanceVariable(libobjc.object_getClass(obj), ensure_bytes(varname))
    vartype = ctype_for_encoding(libobjc.ivar_getTypeEncoding(ivar))

    if not isinstance(value, vartype):
        raise TypeError(
            "Incompatible type for ivar {!r}: {!r} is not a subclass of the ivar's type {!r}"
            .format(varname, type(value), vartype)
        )
    elif sizeof(type(value)) != sizeof(vartype):
        raise TypeError(
            "Incompatible type for ivar {!r}: {!r} has size {}, but the ivar's type {!r} has size {}"
            .format(varname, type(value), sizeof(type(value)), vartype, sizeof(vartype))
        )

    if weak:
        libobjc.objc_storeWeak(obj.value + libobjc.ivar_getOffset(ivar), value)
    elif issubclass(vartype, objc_id):
        libobjc.object_setIvar(obj, ivar, value)
    else:
        memmove(obj.value + libobjc.ivar_getOffset(ivar), addressof(value), sizeof(vartype))
def set_ivar ( obj , varname , value , weak = False ) : try : obj = obj . _as_parameter_ except AttributeError : pass ivar = libobjc . class_getInstanceVariable ( libobjc . object_getClass ( obj ) , ensure_bytes ( varname ) ) vartype = ctype_for_encoding ( libobjc . ivar_getTypeEncoding ( ivar ) ) if not isinstance ( value , vartype ) : raise TypeError ( "Incompatible type for ivar {!r}: {!r} is not a subclass of the ivar's type {!r}" . format ( varname , type ( value ) , vartype ) ) elif sizeof ( type ( value ) ) != sizeof ( vartype ) : raise TypeError ( "Incompatible type for ivar {!r}: {!r} has size {}, but the ivar's type {!r} has size {}" . format ( varname , type ( value ) , sizeof ( type ( value ) ) , vartype , sizeof ( vartype ) ) ) if weak : libobjc . objc_storeWeak ( obj . value + libobjc . ivar_getOffset ( ivar ) , value ) elif issubclass ( vartype , objc_id ) : libobjc . object_setIvar ( obj , ivar , value ) else : memmove ( obj . value + libobjc . ivar_getOffset ( ivar ) , addressof ( value ) , sizeof ( vartype ) )