diff --git a/PythonForVideoMemos/VMPython/VMPythonResourceDownloader/VMPythonResourceDownloader.m b/PythonForVideoMemos/VMPython/VMPythonResourceDownloader/VMPythonResourceDownloader.m index 2bfa535..7d03e4a 100644 --- a/PythonForVideoMemos/VMPython/VMPythonResourceDownloader/VMPythonResourceDownloader.m +++ b/PythonForVideoMemos/VMPython/VMPythonResourceDownloader/VMPythonResourceDownloader.m @@ -56,8 +56,8 @@ @implementation VMPythonResourceDownloader - (void)dealloc { - if (self.downloadingOperationQueue) { - [self.downloadingOperationQueue cancelAllOperations]; + if (_downloadingOperationQueue) { + [_downloadingOperationQueue cancelAllOperations]; } } @@ -82,6 +82,19 @@ - (instancetype)init #pragma mark - Getter +- (NSOperationQueue *)downloadingOperationQueue +{ + if (!_downloadingOperationQueue) { + _downloadingOperationQueue = [[NSOperationQueue alloc] init]; + _downloadingOperationQueue.maxConcurrentOperationCount = 1; + _downloadingOperationQueue.suspended = self.suspended; + _downloadingOperationQueue.qualityOfService = NSQualityOfServiceUtility; + } + // Set `suspended=YES` if want to pause all operations temporary. + //self.downloadingOperationQueue.suspended = YES; + return _downloadingOperationQueue; +} + - (NSCharacterSet *)invalidFilenameCharacterSet { if (!_invalidFilenameCharacterSet) { @@ -221,9 +234,7 @@ - (void)setSuspended:(BOOL)suspended { _suspended = suspended; - if (self.downloadingOperationQueue) { - self.downloadingOperationQueue.suspended = self.suspended; - } + self.downloadingOperationQueue.suspended = self.suspended; } #pragma mark - Public @@ -308,14 +319,6 @@ - (NSString *)downloadWithURLString:(NSString *)urlString preferredName:(NSString *)preferredName userInfo:(NSDictionary *)userInfo { - if (!self.downloadingOperationQueue) { - self.downloadingOperationQueue = [[NSOperationQueue alloc] init]; - self.downloadingOperationQueue.maxConcurrentOperationCount = 1; - self.downloadingOperationQueue.suspended = self.suspended; - } - // Set `suspended=YES` if want to pause all operations temporary. - //self.downloadingOperationQueue.suspended = YES; - VMPythonDownloadOperation *operation = [[VMPythonDownloadOperation alloc] initWithURLString:urlString inFormat:format totalFileSize:totalFileSize