How does the stop
mechanism work in this code?
@interface GifAnaimator()
@property BOOL stopping;
@end
@implementation GifAnaimator
- (void)startWithURL:(CFURLRef)imageURL {
__weak GifAnaimator *weakSelf = self;
CGAnimateImageAtURLWithBlock(imageURL, nil, ^(size_t index, CGImageRef image, bool* stop) {
// Some image handling code...
*stop = weakSelf.stopping;
});
}
- (void)stop {
self.stopping = YES;
}
@end
What's confusing me about this code is that the dereferenced stop
is assigned a plain, non-pointed to, BOOL
, stopping
. Afterwards, when stopping
is mutated, stop
somehow gets the same mutation.
I tried capturing stop
in a block, and calling the block later on to mutate it like so:
weakSelf.stopAnimation = ^{
*stop = YES;
};
This code makes more sense to me but it doesn't work.
What exactly is happening here?