EXC_BAD_ACCESS if I call an Objective-C block directly

Continuing to try to understand the blocks in Objective-C. I have the following function:

typedef void(^TAnimation)(void);
TAnimation makeAnim(UIView *aView, CGFloat angle, CGFloat x, CGFloat y, 
                    CGFloat width, CGFloat height, UIInterfaceOrientation uiio) {
    return Block_copy(^{
        aView.transform = CGAffineTransformMakeRotation(angle);
        aView.frame = CGRectMake(x, y, width, height);
        [UIApplication sharedApplication].statusBarOrientation = uiio;
    });
}

When I try to do the following:

TAnimation f = makeAnim( ... );
f();

I get EXC_BAD_ACCESS. However, if I do the following:

TAnimation f = makeAnim( ... );
[UIView animateWithDuration:0 delay:0 options:0 animations:f completion:NULL];

It works great. What is the problem in the first scenario?

+3
source share
2 answers

NSZombieEnabled. , NSZombie, , , . NSZombieEnabled, , "" NSZombieEnable yes ", :".

+1

:

#import <Foundation/Foundation.h>

typedef void(^printerBlock)(void);

printerBlock createPrinter(NSString *thingToPrint) {
    return Block_copy(^{
        NSLog(@"Printing: %@", thingToPrint);
    });
}

int main (int argc, char const* argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    printerBlock pb = createPrinter(@"Testing string.");
    pb();

    [pool drain];
    return 0;
}

:

2011-10-22 21:28:14.316 blocker[12834:707] Printing: Testing string.

"", - , - . , , NSZombieEnabled .

, , , .

, , , .

0

Source: https://habr.com/ru/post/1769915/


All Articles