报错误Dereferencing a __weak pointer is not allowed due to possible null value caused by race condition, assign it to strong variable first
//
// ViewController.m
// __block__weak
//
// Created by apple on 15/12/25.
// Copyright © 2015年 apple. All rights reserved.
//
#import "ViewController.h"
#import "ViewController2.h"
typedef void(^ViewBlock)();
@interface ViewController (){
NSString * str;
}
@property (nonatomic,copy) ViewBlock block;
@end
@implementation ViewController
- (void)dealloc {
NSLog(@"v1 dealloc!");
}
- (void)viewDidLoad {
[super viewDidLoad];
str = @"123";
__weak typeof(self) blockSelf = self;
self.block = ^(){
//报错误Dereferencing a __weak pointer is not allowed due to possible null value caused by race condition, assign it to strong variable first
//需要加下面一个来强引用blockSelf
ViewController *strongSelf = blockSelf;
NSLog(@"%@",strongSelf->str);
};
}
@end