gpt4 book ai didi

ios - Swift 相当于 "[[transferManager download:downloadRequest] continueWithExecutor:[AWSExecutor mainThreadExecutor] withBlock:^id(AWSTask *task)"

转载 作者:行者123 更新时间:2023-11-28 06:26:22 27 4
gpt4 key购买 nike

是否有 Swift 3.0 等同于:

[[transferManager download:downloadRequest] continueWithExecutor:[AWSExecutor mainThreadExecutor] withBlock:^id(AWSTask *task)

这是 Objective-C 实现(在 S3 iOS documentation 上我找不到 Swift 示例)。

Objective-C 代码(来自 AWS 文档):

     [[transferManager download:downloadRequest] continueWithExecutor:[AWSExecutor mainThreadExecutor] withBlock:^id(AWSTask *task) {

NSLog(@"Task is continuing..");

if (task.error){
if ([task.error.domain isEqualToString:AWSS3TransferManagerErrorDomain]) {
switch (task.error.code) {
case AWSS3TransferManagerErrorCancelled:
case AWSS3TransferManagerErrorPaused:
break;

default:
NSLog(@"Error: %@", task.error);
break;
}
} else {
// Unknown error.
NSLog(@"Error: %@", task.error);
}
}

if (task.result) {
// File downloaded successfuly
NSLog(@"File downloaded successfuly");
AWSS3TransferManagerDownloadOutput *downloadOutput = task.result;

// Put this in hte right place
//self.imageView.image = [UIImage imageWithContentsOfFile:downloadingFilePath];

//File downloaded successfully.
}
return nil;
}];

最佳答案

应该是 transferManager.download(downloadRequest).continueWithBlock({ (task) -> AnyObject!in

您还可以找到 Swift 翻译 here :

func download(downloadRequest: AWSS3TransferManagerDownloadRequest) {
switch (downloadRequest.state) {
case .NotStarted, .Paused:
let transferManager = AWSS3TransferManager.defaultS3TransferManager()
transferManager.download(downloadRequest).continueWithBlock({ (task) -> AnyObject! in
if let error = task.error {
if error.domain == AWSS3TransferManagerErrorDomain as String
&& AWSS3TransferManagerErrorType(rawValue: error.code) == AWSS3TransferManagerErrorType.Paused {
print("Download paused.")
} else {
print("download failed: [\(error)]")
}
} else if let exception = task.exception {
print("download failed: [\(exception)]")
} else {
dispatch_async(dispatch_get_main_queue(), { () -> Void in
if let index = self.indexOfDownloadRequest(self.downloadRequests, downloadRequest: downloadRequest) {
self.downloadRequests[index] = nil
self.downloadFileURLs[index] = downloadRequest.downloadingFileURL

let indexPath = NSIndexPath(forRow: index, inSection: 0)
self.collectionView.reloadItemsAtIndexPaths([indexPath])
}
})
}
return nil
})

break
default:
break
}
}

关于ios - Swift 相当于 "[[transferManager download:downloadRequest] continueWithExecutor:[AWSExecutor mainThreadExecutor] withBlock:^id(AWSTask *task)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41766407/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com