omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    4
    6
    2723
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ryubai
      ryubai last edited by

      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 advance

      RuntimeError: 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)

      mikael 1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • mikael
          mikael @ryubai last edited by

          @ryubai, do this:

          try:
              Handler
          except NameError:
              class Handler(NSObject):
                  ...
          
          1 Reply Last reply Reply Quote 0
          • JonB
            JonB last edited by

            That only works if your class is stable -- if you need to change it, you will have to force quit the app.

            ryubai 1 Reply Last reply Reply Quote 1
            • ryubai
              ryubai @JonB last edited by

              @JonB

              thanks.
              it seems not convenient for debug, and i still use objc_util as OC bridge.

              1 Reply Last reply Reply Quote 0
              • dgelessus
                dgelessus last edited by

                For reference, @JonB has opened an issue for this feature on the rubicon.objc issue tracker: https://github.com/beeware/rubicon-objc/issues/181

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Powered by NodeBB Forums | Contributors