@property (nonatomic, strong) NSArray *friendsList;
// some method
...
[FBRequestConnection startWithGraphPath:@"/me/friends" parameters:nil HTTPMethod:@"GET" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
_friendsList = [result objectForKey:@"data"];
}];
我的代码是否正确?我没有任何警告和代码构建没有错误,所有工作都很好,但我想知道,如果有任何隐藏的问题,如隐式保留?
答案 0 :(得分:0)
该行
_friendsList = [result objectForKey:@"data"];
表示
self->_friendsList = [result objectForKey:@"data"];
该行保留自己,如果不是问题,那么一切都很好。如果有问题,可以使用:
__weak typeof(self) selfWeak = self;
FBRequestConnection startWithGraphPath:@"/me/friends" parameters:nil HTTPMethod:@"GET" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
__strong typeof(selfWeak) selfStrong = selfWeak;
if(selfStrong)
{
selfStrong.friendsList = [result objectForKey:@"data"];
}
}];