Create a new class if it already exists while subclassing with rubicon.objc
I won't make a pull request because it's a very hacky workaround for scripts running in the same process
@@ -656,10 +656,16 @@ class ObjCClass(ObjCInstance, type):
@classmethod
def _new_from_class_statement(cls, name, bases, attrs, *, protocols):
- name = ensure_bytes(name)
- if get_class(name).value is not None:
- raise RuntimeError('An Objective-C class named {!r} already exists'.format(name))
+ exists = False
+ if get_class(ensure_bytes(name)).value is not None:
+ i = 2
+ while get_class(ensure_bytes(name+str(i))).value is not None:
+ i += 1
+
+ name = name+str(i)
+
+ name = ensure_bytes(name)
try:
(superclass,) = bases
@@ -1444,7 +1450,14 @@ class Block:
self._as_parameter_ = self.block
def wrapper(self, instance, *args):
- return self.func(*args)
+ _args = ()
+ for arg in args:
+ if isinstance(arg, objc_id):
+ _args += (ObjCInstance(arg),)
+ else:
+ _args += (arg,)
+
+ return self.func(*_args)
def dispose_helper(self, dst):
Block._keep_alive_blocks_.pop(dst, None)
