Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8240715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:35:06+00:00 2026-06-07T20:35:06+00:00

I have a objc method like this; @ implementation of Class1 – (void)execute:(void (^)(Class2*

  • 0

I have a objc method like this;

@ implementation of Class1

- (void)execute:(void (^)(Class2* target, NSUInteger idx))block
{
... 

}

I want to use this execute method in python, i have build a python objective-c bridge data and it seems to be generated correctly as:

<class name='Class1'>
<method selector='execute:'>
<arg function_pointer='true' type='@?' index='0'>
    <arg type='@'/>
    <arg type='I' type64='Q'/>
    <retval type='v'/>
</arg>
</method>

But when i define a function like this:

def myFunc (dev, index):
    // do something with dev
    print("Hello")

and try to use this as block

class1_obj.execute_(myFunc)

Python throw an errors as:

objc.BadPrototypeError: Objective-C expects 1 arguments, Python argument has 2 arguments for <unbound selector myFunc at 0x105b3a3f0>

I also tried with lambda function, no use.

I also tried to create a callable class as:

>>> class myCallable(object):
...     def __init__(self,name):
...             print "Init"
...     def __repr__(self):
...             return "string init"
...     def __call__(self, dev, index):
...             # do something with dev
...             print("hello")

but python throw an error like this:

TypeError: Sorry, cannot create IMP for instances of type myCallable

I am wondering where did I do wrong here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T20:35:08+00:00Added an answer on June 7, 2026 at 8:35 pm

    Thanks for Josh’s suggestion.

    Finally got this problem solved. It looks like the meta_data generated by the system using command line gen_bridge_metadata somehow wasn’t read correctly. It was generated as:

    <method selector='execute:'>
    <arg index='0' type='@?' function_pointer='true'>
    <arg type='@'/>
    <arg type64='Q' type='I'/>
    <retval type='v'/>
    </arg>
    </method>
    

    But after I change the function_pointer to block, it works. I got this by reading through pyobjc unit test for blocks.

    <method selector='execute:'>
    <arg index='0' type='@?' block='true'>
    <arg type='@'/>
    <arg type64='Q' type='I'/>
    <retval type='v'/>
    </arg>
    </method>
    

    I am not sure what causes this though. the Apple Doc says if type=”@?” and function_pointer=’true’, it’s regarded as block. if type = “#?” and function_pointer=”true”, it will interpreted as function_pointer. but why pyobjc can’t recognize this? is this a bug in pyobjc?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Obj-C method similar to this: -(void)getUserDefaults:(BOOL *)refreshDefaults { PostAppDelegate *appDelegate =
In my objective-c project, I have a protocol like this: @protocol MyProtocol -(id) get:(NSString
I have a class method returning a CGSize and I'd like to call it
Inside my Table view controller I have following method -(BOOL)isValidCoordinate:(CLLocationCoordinate2D)coordinate { //This is just
i'd like to have a function in api style. But implementation must be on
Im new to objC and Im currently experimenting on UISearchDisplayController. Basically I have an
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I have searched many questions on ObjC accessors and synthesized accessors to no avail.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.