내 클래스에 hotspotsOperation이라는 인스턴스 변수가 있고 (RestKit을 사용하고 있습니다) 블록 (RestKit의 NSOperation) 내에서 사용됩니다. 진행중인 요청을 취소 할 수 있기를 원하므로이 작업을 수행합니다. 그러나 유지 사이클에 대한 질문이 있습니다. __block. 기본적으로 weakify/strongify를 사용할 때는 __weak을 사용해야합니까? 또 다른 질문으로, 약화/강화는 사용하지 않지만 핫스팟을 변경하는 경우 분석기는 강력한 순환에서 약한 순환으로 작동하지 않으면 보유주기가 없다고 말합니다. 맞습니까? 약화/강화보다는 약한 것을 사용하는 것이 더 낫습니다. 이 경우 자기가 어떻게됩니까? 제안 해 주셔서 감사합니다. 당신이 관리 RestKit에 떨어져 작업을 통과하기 때문에@weakify, @strongify를 사용할 때 __block을 사용해야합니까?
#import "HotspotsService.h"
#import "Constants.h"
#import "Restkit.h"
#import "Hotspot.h"
#import <EXTScope.h>
@interface HotspotsService()
@property (nonatomic,strong) RKObjectManager *objectManager;
@property (nonatomic,strong) RKObjectRequestOperation *hotspotsOperation;
@end
@implementation HotspotsService
-(id) init {
self=[super init];
if (self) {
// restkit
// mapping
// response
}
return self;
}
-(void) hotspotsWithRadius:(NSUInteger)rad center:(CLLocationCoordinate2D)coordinate onSuccess:(void(^)(NSArray *hotspots))success onFailure:(void(^)(NSError *error))fail {
[self cancelHotspotsRequest];
NSDictionary *params = // params
self.hotspotsOperation = [self.objectManager appropriateObjectRequestOperationWithObject:nil method:RKRequestMethodGET path:kSolrPath parameters:params];
@weakify(self);
[self.hotspotsOperation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
@strongify(self);
self.hotspotsOperation=nil;
success(mappingResult.array);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
@strongify(self);
self.hotspotsOperation=nil;
fail(error);
}];
[self.objectManager enqueueObjectRequestOperation:self.hotspotsOperation];
}
-(void) cancelHotspotsRequest {
[self.hotspotsOperation cancel];
self.hotspotsOperation=nil;
}
@end
왜 그냥'cancelAllObjectRequestOperationsWithMethod : matchingPathPattern :'을 사용하지 않으시겠습니까? – Wain
답장을 보내 주셔서 감사합니다. 이 경우에는 작동하지만 문제는 내가 취소하고 싶지 않은 다른 요청이 동시에있을 수 있다는 것입니다. 어쨌든, 제 질문은 블록 유지주기 관리에 관한 것입니다. 어떠한 제안? 감사. – Ricardo