oc의 리셋 함정 조심

794 단어
오늘 코드를 디버깅하고 숨겨진 BUG를 발견했습니다.다음 코드:
for(NSString *filename in sorted){
        
        NSString *filepath = [[YLSGlobalUtils getCurrentEnterpriseDirPath] stringByAppendingPathComponent:filename];
        
        [component uploadFileAt:filepath toURL:url ProcessHandler:processHandler CompletionHandler:^(NSDictionary* response){
            
            [fileManager removeItemAtPath:filepath error:nil];//         
            
        }];
        
    }

원래 뜻은 파일을 반복해서 업로드하고 로컬 파일을 삭제하는 것입니다. 그러나 이 코드는 BUG가 있습니다.이것 때문에
Block에서 이 줄로 이동할 때 비동기적으로 리셋합니다.
[fileManager removeItemAtPath:filepath error:nil];//         

filepath는 현재 값을 순환하는 것이 아니라
항상 마지막으로 순환하는 값이기 때문에 마지막 파일만 삭제됩니다
그래서 순환체 안의 비동기적인 리셋과 관련되므로 이 문제를 조심해야 한다

좋은 웹페이지 즐겨찾기