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

  • Home
  • SEARCH
  • 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 8431381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:50:23+00:00 2026-06-10T05:50:23+00:00

Is it possible to define an Objective-C block property but still have full-code completion

  • 0

Is it possible to define an Objective-C block property but still have full-code completion in Xcode 4?

If I use a typedef to define the block:

typedef void (^CompletionBlock)(MyObject *myObj);

and then define the property:

@property (nonatomic, copy) CompletionBlock completionBlock;

and then @synthesize the property I don’t get full code completion when calling the setter. Xcode will use the typedef and because of this, the code completion doesn’t use the full block syntax complete with block parameters, it uses the typedef.

If I define a method prototype in the header that uses the full block syntax instead of the typedef:

@property (nonatomic, copy) void (^completionBlock)(MyObject *myObj);

and then I use @synthesize, the provided setter comes close to using the full code completion syntax but crucially it leaves out the parameter names:

[self setCompletionBlock:(void (^)(MyObject *)) { ... }

Finally, if I try to @synthesize and then override the setter implementation or put the prototype in the header:

- (void)setCompletionBlock:(void (^)(MyObject *myObj))completionBlock {...}

A warning is raised stating that the property type does not match the accessor type. No matter how I try to finagle the syntax, I’m not able to both define a block property and a setter that has the full syntax for code completion. Can I have my cake and eat it too?

Thanks!

  • 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-10T05:50:25+00:00Added an answer on June 10, 2026 at 5:50 am

    You can definitely have your cake and eat it too, if you are willing to add one extra line of code to your class interface.

    First, define block with a typedef and create a property like you did in your question:

    typedef void (^CompletionBlock)(MyObject *myObj);
    
    ...
    
    @property (nonatomic, copy) CompletionBlock completionBlock;
    

    Next, as MobileOverload pointed out in his answer, we know that Xcode provides correct code completion for typedef’d blocks if used in a standalone method declaration. So, let’s add an explicit declaration for the setter of completionBlock:

    - (void)setCompletionBlock:(CompletionBlock)completionBlock;
    

    When called, this method resolves to the setter method declared by the property. However, because we explicitly defined it in the class interface, Xcode sees it and applies full code completion.

    So, if you include all three of those lines you should get the desired result. This behavior is clearly a shortcoming of Xcode, as there is no reason why a setter defined in a @property statement should have different code completion than the same method defined on its own.

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

Sidebar

Related Questions

Is it possible to use some thing like this in Objective-C: #define number_of_items 10
Possible Duplicate: Define a method that has many (or infinite) arguments I have the
Is it possible to define an interface (e.g. MyClass Implements MyInterface) whose method/property definitions
Possible Duplicate: Objective-C Default Argument Value I couldn't find a way to define a
Is it possible to dynamically define methods in Objective-C like we would in Ruby?
Possible Duplicate: Best way to define private methods for a class in Objective-C Hi,
Possible Duplicate: Properties declared as instance variables too? Let's say I have an objective
Is it possible to define classes at run time in objective-c? E.g. I receive
I know it's possible to define public instance variable with @public keyword. However, Objective-C
Possible Duplicate: Is it possible to define enumalpha? Is there any equivalent of Java

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.