Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
rubicon.objc’s problem
-
latest when i try rubicon_objc.
the code below, run once is normal. run anther time will raise a err.
how can i solve it? thanks in advanceRuntimeError: An Objective-C class named b'Handler' already exists
code:
from rubicon.objc import NSObject, objc_method
class Handler(NSObject):
@objc_method
def initWithValue_(self, v: int):
self.value = v
return self@objc_method def pokeWithValue_andName_(self, v: int, name) -> float: print("My name is", name) return v / 2.0
my_handler = Handler.alloc().initWithValue(42)
-
I'm not sure how Rubicon handles things -- for objc_util, the way it handles that is by renaming the objc class -- so if you define Handler again, it will create a class called Handler1. There is a debug flag that allows this. The problem is that objc runtime does not allow deletion of classes or creating a new class with the same name.
-
@ryubai, do this:
try: Handler except NameError: class Handler(NSObject): ...
-
That only works if your class is stable -- if you need to change it, you will have to force quit the app.
-
thanks.
it seems not convenient for debug, and i still use objc_util as OC bridge. -
For reference, @JonB has opened an issue for this feature on the rubicon.objc issue tracker: https://github.com/beeware/rubicon-objc/issues/181