我有一个类,类中有一个属性@property (nonatomic, assign) NSMutableArray *images
我有一个block循环,循环中会去往这个可变数组中加数据:
__weak typeof(self) weakSelf = self;
[array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
UIImageView *image = [[UIImageView alloc] init];
[weakSelf.images addObject:image]; // 有时会在这儿崩溃
}];
// 我在出block之后,打印数据
NSLog(@"count : %lu", _images.count); // 有时会出现值
for (int i =0 ; i< _images.count; i++) { // 如果上面没崩溃,这必会崩溃
NSLog(@"image frame : %@", _images[i]);
}
请问,这是什么问题? 我不太懂block这东西。
对于对象类型你申明的时候不要用assign,对于这个问题你要这样申明:
@property (nonatomic, strong) NSMutableArray *images;