我最近转向使用ARC,对于在将self对象传递给block时设置正确的属性值有些困惑。
据我理解,任何用_weak声明的属性都不应该在dealloc方法中被设置为nil。而传递给block的self对象应该使用_weak声明,而不是__block。
如果我的理解是正确的,并且我在下面的实现中做得正确,请让我知道。
(void)myApplication {
self.data = [NSMutableDictionary dictionary];
__weak MyViewController *aBlockSelf = self;
[self.data setValue:[MyAction customActionWithBlock:^(MyAction *iAction, NSString *iIdentifier) {
AnotherViewController *aController = [[AnotherViewController alloc] initWithType:@"aType"];
aController.hasSearch = NO;
aController.delegate = aBlockSelf;
aController.showInventoryImage = YES;
[aBlockSelf presentNavigationalModalViewController: aController];
}] forKey:@"aKey"];
}