开发者

If you define an Objective C block within a block within a function, what scope does the inner block have access to?

开发者 https://www.devze.com 2023-04-02 05:24 出处:网络
If one def开发者_JAVA技巧ines a block within a block within a function, what scope does the inner block have access to.

If one def开发者_JAVA技巧ines a block within a block within a function,

what scope does the inner block have access to.

Also, would you have to do this to prevent retaining of self(pretend blocks are formed properly):

-(void)function
{
__block id me = self;
^{
     __block id me2 = me;
    ^{
        [me2 ...];
    ^}
^}
}


I have blocks of the form

-(void) function
{
    __block bool isOK = true;
    // ...
    [someArray enumerateObjectsWithBlock: ^(id obj, bool** stop)
    {
        // ...
        [someOtherArray enumerateObjectsWithBlock: ^(id obj, bool** stop)
        {
           // ...
           isOK = false;
        }];
    }];
}

So the inner block has access to the scope of the outer block.

Why do you want to prevent self from being retained? The object has to sty around for the lifetime of the blocks anyway.

0

精彩评论

暂无评论...
验证码 换一张
取 消