Objective c NSmutualArray中奇怪的NSZombie错误
几天前我遇到了一个奇怪的错误。幸运的是,我在4-5天内解决了这个错误。然而,我只是想知道为什么会发生这种错误 首先,我将用相同的代码示例描述这种情况Objective c NSmutualArray中奇怪的NSZombie错误,objective-c,nsarray,nsdictionary,objective-c-blocks,nszombie,Objective C,Nsarray,Nsdictionary,Objective C Blocks,Nszombie,几天前我遇到了一个奇怪的错误。幸运的是,我在4-5天内解决了这个错误。然而,我只是想知道为什么会发生这种错误 首先,我将用相同的代码示例描述这种情况 @interface SampleViewController () @property (nonatomic, strong) NSMutableArray *selectedIssue; @property (nonatomic, strong) NSOperationQueue *queueJSON; @property (nonatomi
@interface SampleViewController ()
@property (nonatomic, strong) NSMutableArray *selectedIssue;
@property (nonatomic, strong) NSOperationQueue *queueJSON;
@property (nonatomic, strong) NSOperationQueue *queueImage;
@end
@implementation SampleViewController
/** blah blah blah*/
- (void) fillIssueArrayMethodWithIssueId:(NSInteger) selectedId {
NSString *requestURL = [NSString stringWithFormat:@"%@Issues/Get/?id=%d", kAPIRootURL, selectedId];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:requestURL]
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:kNetworkTimeOut];
AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request];
op.responseSerializer = [AFJSONResponseSerializer serializer];
[op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id response) {
NSData *JSONData = [NSData dataWithContentsOfFile:filePath
options:NSDataReadingMappedIfSafe
error:nil];
NSMutableArray *responseObject = [NSJSONSerialization JSONObjectWithData:JSONData
options:NSJSONReadingMutableContainers
error:nil];
if(responseObject) {
if([responseObject isKindOfClass:[NSArray class]]) {
_selectedIssue = [NSMutableArray arrayWithArray:responseObject];
}
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { }];
[_queueJSON addOperation:op];
}
-(void)startDownloadImages {
NSArray *objPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *strPath = [objPaths lastObject];
if(!_queueImage)
_queueImage = [[NSOperationQueue alloc] init];
_queueImage.maxConcurrentOperationCount = 3;
NSBlockOperation *completionOperation = [NSBlockOperation new];
for (__block NSDictionary *object in _selectedIssue) {
// Photos
NSString *imgURL = object[@"ImageUrl"];
NSString *strImageFile = [NSString stringWithFormat:@"%@_%@", object[@"Id"], [imgURL lastPathComponent]];
__block NSString *strImagePath = [NSString stringWithFormat:@"%@/Images/Issues/%@", strPath, strImageFile];
NSURLRequest *request4Images = [NSURLRequest requestWithURL:[NSURL URLWithString:imgURL]];
AFHTTPRequestOperation *operation4Images = [[AFHTTPRequestOperation alloc] initWithRequest:request4Images];
[operation4Images setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id rawResult) {
BOOL isImageWrited = [rawResult writeToFile:strImagePath options:NSDataWritingAtomic error:nil];
if(isImageWrited) {
NSLog(@"Image Write Success : %@", operation.request.URL);
} else {
NSLog(@"Image Write Error: %@", imageWriteError.description);
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Image Write Failed : %@ : %ld", operation.request.URL, (long)operation.response.statusCode);
}];
[completionOperation addDependency:operation4Images];
}
[_queueImage addOperations:completionOperation.dependencies waitUntilFinished:NO];
[_queueImage addOperation:completionOperation];
}
@end
这就是问题所在
在应用程序生命周期中,FillIssuarRayMethodWithIssueId方法首先将JSON数据获取到相互数组。然后通过从数组中获取图像URL开始下载图像
每过一秒,我都想用issueid方法访问_selectedissuein fillissuearraymethod,我的应用程序就会崩溃
根据长期的调查,当启动DownloadImages方法完成时,选择的假设立即成为僵尸对象。但是在这个方法中,我从未重新分配过这个数组。我刚刚读取了这个数组中的值。我确信在这种方法中,数组会变成僵尸对象,因此在for循环中移除块时,问题得到了解决
那么问题是,u块类型如何影响u selectedIssue arrays对象
我只想知道我错过了什么
顺便说一句,在for循环之前,我已经尝试过StartDownloadImages方法,我已经创建了临时数组,这个临时数组刚刚用_selectedissuemutablecopy或just copy启动。然而,我再次面临僵尸问题。你的问题很难理解。您这么说,问题在删除时得到了解决。请键入for循环块,但我在您发布的代码中没有看到任何\uu块。@newacct是的,我使用了arc。@特洛伊木马程序\uu块在for语句中