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 7756737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:53:59+00:00 2026-06-01T12:53:59+00:00

Consider: typedef void (^select_block_t)(UIView *) ; (1) @property (copy, nonatomic) select_block_t myBlockProperty ; (2)

  • 0

Consider:

typedef void (^select_block_t)(UIView *) ;

(1) @property (copy, nonatomic) select_block_t        myBlockProperty ;
(2) @property (strong, nonatomic) select_block_t      myBlockProperty ;
(3) @property (assign, nonatomic) select_block_t      myBlockProperty ;

and:

(A) self.myBlockProperty = ^(UIView *) {NSLog(@"Hi");} ;
(B) self.myBlockProperty = [^(UIView *) {NSLog(@"Hi");} copy] ;

I am trying to understand what is the correct way to map which property declaration with which block copy semantics

I have seen examples here on S.O. that would favor[1:B]

But then I get confused by how redundant the ‘copy’ operation is.
My limited understanding is that [1:A] should be correct, because I want
the block to be copied once when I assign the property, not once at block creation and then once again at property assignment time.

[3:B] would also make sense according to my rationale. So, what am I misunderstanding?

  • 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-01T12:54:00+00:00Added an answer on June 1, 2026 at 12:54 pm

    [1:A] is correct, yes. [3:B] is incorrect because:

    1. it’s not clear that the class owns the property, so should release it in dealloc (but it should)
    2. the setter (B) looks like a leak, and the static analyser might flag it as such, because the block is copied, handed to a property, then leaves the scope with retain count +1.
    3. using (3) means that it only works if you set a heap-block (a copied block) with a retain count of one. This leaves plenty of margin for error when using the property. (1) works with both stack-blocks and heap-blocks, and will also correctly retain auto-released blocks.

    EDIT: I see you’re using ARC. In that case, it’s not possible to use [3:B] at all. The compiler will release an object (even when copyed) once it’s out of scope, and this property setter won’t have retained it. Therefore the property will contain a bad pointer, it’s an EXC_BAD_ACCESS waiting to happen.

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

Sidebar

Related Questions

Consider this program: #include <map> #include <vector> typedef std::vector<int> IntVector; typedef std::map<IntVector,double> Map; void
Consider following code: main.cpp: #include <iostream> typedef void ( * fncptr)(void); extern void externalfunc(void);
Consider: template < typename Something > boost::function<void()> f() { typedef typename Something::what type; return
Consider the following excerpt from the safe bool idiom : typedef void (Testable::*bool_type)() const;
Consider the following code: typedef float image_buffer[1024][1024]; void f(image_buffer *b) { for (int i
Consider the following program: #include <iostream> typedef void (*fptr)(...); void foo(fptr func) { (*func)(12);
Consider the following C program: #include <stdio.h> #include <stdarg.h> typedef void callptr(); static void
Consider the following: template <typename T> class testString { public: typedef T* iterator; void
Consider the following: typedef struct { int a; int b; int c; int d;
Consider the following function template: template<typename T> void Foo(T) { // ... } Pass-by-value

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.