我已经阅读了 Apple 的 Blocks Programming Topics 和我的尽职调查在线搜索,但我仍然不清楚我是否正确实施了我的块。我有一组客户端作为发送 NSNotification 时填充的属性。Clients 用作 tableview 数据源。下面的代码有效,但我很好奇它是否将 self 置于保留周期中。我应该做类似的事情__block id theClients = self.clients;
然后theClients
在块内引用吗?
@property (strong, nonatomic) NSMutableArray *clients;
NSNotificationCenter *notifyCenter = [NSNotificationCenter defaultCenter];
__block id observer = [notifyCenter addObserverForName:queryHash
object:nil
queue:[[NSOperationQueue alloc] init]
usingBlock:^(NSNotification* notification){
// Explore notification
if ([[notification.userInfo objectForKey:kdatasetReturnKey] objectAtIndex:0]) {
NSArray *rows = [[notification.userInfo objectForKey:kdatasetReturnKey] objectAtIndex:0];
if (self.clients)
{
self.clients = nil;
}
self.clients = [[NSMutableArray alloc] initWithCapacity:rows.count];
for (NSDictionary *row in rows) {
[self.clients addObject:row];
}
} else {
NSLog(@"CLIENTS ERROR Returned: %@",[notification.userInfo objectForKey:kerrorReturnKey]);
}
[[NSNotificationCenter defaultCenter] removeObserver:observer];
}];