开发者

If you define an Objective C 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜