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.


    How can I use return in my objC class

    Pythonista
    objcutil
    2
    3
    1797
    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.
    • watosar
      watosar last edited by

      from objc_util import *
      
      def foo_bar(_self,_cmd):
      	baz = c_int()
      	return baz
      	
      foo=create_objc_class('foo',methods=[foo_bar])
      foo = foo.alloc()
      foo.bar.restype = c_int
      
      print('out',foo.bar())
      

      This returned

      out None
      

      I couldn’t found what I have to do.
      Please teach me.

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

        first, you need to call .alloc().init(). well, in this case you don't, but if you send this object to other objc code it will crash if you dont,

        second, you need to set encoding, and optionally restype, AND argtypes. (restype only works if argtypes is also specified). This must be done before you call create_objc_class. Most import is the encoding.

        Also, you just return normal python types, and the callback mechanism takes care of converting.

        Here is you code, updated, along with a description of the type encodings. see objc_util source for more details
        https://gist.github.com/d1b10d812306a749335e052eb5e1af9e

        1 Reply Last reply Reply Quote 1
        • watosar
          watosar last edited by

          Thank you!!!!

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