美文网首页
block重新赋值后判断是否相等

block重新赋值后判断是否相等

作者: 王家薪 | 来源:发表于2017-09-07 16:01 被阅读18次
    @property (nonatomic, copy)  void(^block)();
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        self.block = ^{
            NSLog(@"123");
        };
        void * a = (__bridge void *)(_block);
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            if (a == _block) {
                self.block();
            }
        });
        self.block = ^{
            NSLog(@"456");
        };
    }
    

    不输出

    @property (nonatomic, copy)  void(^block)();
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        self.block = ^{
            NSLog(@"123");
        };
        void * a = (__bridge void *)(_block);
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            if (a == _block) {
                self.block();
            }
        });
    }
    

    输出 123

    相关文章

      网友评论

          本文标题:block重新赋值后判断是否相等

          本文链接:https://www.haomeiwen.com/subject/zvmijxtx.html