Copying blocks (ie: copying them to instance variables) in Objective-C

后端 未结 4 1321
[愿得一人]
[愿得一人] 2020-12-08 21:31

I\'m trying to understand blocks. I get how to use them normally, when passed directly to a method. I\'m interested now in taking a block, storing it (say) in an instance va

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-08 22:01

    You'll want to do this instead:

    - (void) setupStoredBlock
    {
        int salt = 42;
        m_storedBlock = Block_copy(^(int incoming){ return 2 + incoming + salt; });
    }
    

提交回复
热议问题