(cls, object_ptr, _name=None, _bases=None, _ns=None)
return self
The constructor accepts an :class:`~rubicon.objc.runtime.objc_id` or anything that can be cast to one,
        such as a :class:`~ctypes.c_void_p`, or an existing :class:`ObjCInstance`.

        :class:`ObjCInstance` objects are cached --- this means that for every Objective-C object
        there can be at most one :class:`ObjCInstance` object at any time. Rubicon will automatically create
        new :class:`ObjCInstance`\\s or return existing ones as needed.

        The returned object's Python class is not always exactly :class:`ObjCInstance`. For example,
        if the passed pointer refers to a class or a metaclass, an instance of :class:`ObjCClass`
        or :class:`ObjCMetaClass` is returned as appropriate. Additional custom :class:`ObjCInstance` subclasses
        may be defined and registered using :func:`register_type_for_objcclass`.
        Creating an :class:`ObjCInstance` from a ``nil`` pointer returns ``None``.

        Rubicon currently does not perform any automatic memory management on the Objective-C object
        wrapped in an :class:`ObjCInstance`. It is the user's responsibility to ``retain`` and ``release``
        wrapped objects as needed, like in Objective-C code without automatic reference counting.
The constructor accepts an :class:`~rubicon.objc.runtime.objc_id` or anything that can be cast to one,
        such as a :class:`~ctypes.c_void_p`, or an existing :class:`ObjCInstance`.
The constructor accepts an : class : ~rubicon . objc . runtime . objc_id or anything that can be cast to one such as a : class : ~ctypes . c_void_p or an existing : class : ObjCInstance .
def __new__(cls, object_ptr, _name=None, _bases=None, _ns=None):
        """The constructor accepts an :class:`~rubicon.objc.runtime.objc_id` or anything that can be cast to one,
        such as a :class:`~ctypes.c_void_p`, or an existing :class:`ObjCInstance`.

        :class:`ObjCInstance` objects are cached --- this means that for every Objective-C object
        there can be at most one :class:`ObjCInstance` object at any time. Rubicon will automatically create
        new :class:`ObjCInstance`\\s or return existing ones as needed.

        The returned object's Python class is not always exactly :class:`ObjCInstance`. For example,
        if the passed pointer refers to a class or a metaclass, an instance of :class:`ObjCClass`
        or :class:`ObjCMetaClass` is returned as appropriate. Additional custom :class:`ObjCInstance` subclasses
        may be defined and registered using :func:`register_type_for_objcclass`.
        Creating an :class:`ObjCInstance` from a ``nil`` pointer returns ``None``.

        Rubicon currently does not perform any automatic memory management on the Objective-C object
        wrapped in an :class:`ObjCInstance`. It is the user's responsibility to ``retain`` and ``release``
        wrapped objects as needed, like in Objective-C code without automatic reference counting.
        """

        # Make sure that object_ptr is wrapped in an objc_id.
        if not isinstance(object_ptr, objc_id):
            object_ptr = cast(object_ptr, objc_id)

        # If given a nil pointer, return None.
        if not object_ptr.value:
            return None

        # If an ObjCInstance already exists for the Objective-C object,
        # reuse it instead of creating a second ObjCInstance for the same object.
        try:
            return cls._cached_objects[object_ptr.value]
        except KeyError:
            pass

        # If the given pointer points to a class, return an ObjCClass instead (if we're not already creating one).
        if not issubclass(cls, ObjCClass) and object_isClass(object_ptr):
            return ObjCClass(object_ptr)

        # Otherwise, create a new ObjCInstance.
        if issubclass(cls, type):
            # Special case for ObjCClass to pass on the class name, bases and namespace to the type constructor.
            self = super().__new__(cls, _name, _bases, _ns)
        else:
            if isinstance(object_ptr, objc_block):
                cls = ObjCBlockInstance
            else:
                cls = type_for_objcclass(libobjc.object_getClass(object_ptr))
            self = super().__new__(cls)
        super(ObjCInstance, type(self)).__setattr__(self, "ptr", object_ptr)
        super(ObjCInstance, type(self)).__setattr__(self, "_as_parameter_", object_ptr)
        super(ObjCInstance, type(self)).__setattr__(self, "_needs_release", False)
        if isinstance(object_ptr, objc_block):
            super(ObjCInstance, type(self)).__setattr__(self, "block", ObjCBlock(object_ptr))
        # Store new object in the dictionary of cached objects, keyed
        # by the (integer) memory address pointed to by the object_ptr.
        cls._cached_objects[object_ptr.value] = self

        return self
def __new__ ( cls , object_ptr , _name = None , _bases = None , _ns = None ) : # Make sure that object_ptr is wrapped in an objc_id. if not isinstance ( object_ptr , objc_id ) : object_ptr = cast ( object_ptr , objc_id ) # If given a nil pointer, return None. if not object_ptr . value : return None # If an ObjCInstance already exists for the Objective-C object, # reuse it instead of creating a second ObjCInstance for the same object. try : return cls . _cached_objects [ object_ptr . value ] except KeyError : pass # If the given pointer points to a class, return an ObjCClass instead (if we're not already creating one). if not issubclass ( cls , ObjCClass ) and object_isClass ( object_ptr ) : return ObjCClass ( object_ptr ) # Otherwise, create a new ObjCInstance. if issubclass ( cls , type ) : # Special case for ObjCClass to pass on the class name, bases and namespace to the type constructor. self = super ( ) . __new__ ( cls , _name , _bases , _ns ) else : if isinstance ( object_ptr , objc_block ) : cls = ObjCBlockInstance else : cls = type_for_objcclass ( libobjc . object_getClass ( object_ptr ) ) self = super ( ) . __new__ ( cls ) super ( ObjCInstance , type ( self ) ) . __setattr__ ( self , "ptr" , object_ptr ) super ( ObjCInstance , type ( self ) ) . __setattr__ ( self , "_as_parameter_" , object_ptr ) super ( ObjCInstance , type ( self ) ) . __setattr__ ( self , "_needs_release" , False ) if isinstance ( object_ptr , objc_block ) : super ( ObjCInstance , type ( self ) ) . __setattr__ ( self , "block" , ObjCBlock ( object_ptr ) ) # Store new object in the dictionary of cached objects, keyed # by the (integer) memory address pointed to by the object_ptr. cls . _cached_objects [ object_ptr . value ] = self return self