官方AWS文档包含以下Objective-c代码
AWSS3TransferUtility *transferUtility = [AWSS3TransferUtility defaultS3TransferUtility]; [transferUtility enumerateToAssignBlocksForUploadTask:^(AWSS3TransferUtilityUploadTask *uploadTask, __autoreleasing AWSS3TransferUtilityUploadProgressBlock *uploadProgressBlockReference, __autoreleasing AWSS3TransferUtilityUploadCompletionHandlerBlock *completionHandlerReference) { NSLog(@"%lu", (unsigned long)uploadTask.taskIdentifier); // Use `uploadTask.taskIdentifier` to determine what blocks to assign. *uploadProgressBlockReference = // Reassign your progress feedback block. *completionHandlerReference = // Reassign your completion handler. } downloadTask:^(AWSS3TransferUtilityDownloadTask *downloadTask, __autoreleasing AWSS3TransferUtilityDownloadProgressBlock *downloadProgressBlockReference, __autoreleasing AWSS3TransferUtilityDownloadCompletionHandlerBlock *completionHandlerReference) { NSLog(@"%lu", (unsigned long)downloadTask.taskIdentifier); // Use `downloadTask.taskIdentifier` to determine what blocks to assign. *downloadProgressBlockReference = // Reassign your progress feedback block. *completionHandlerReference = // Reassign your completion handler. }];
我尝试将其转换为Swift 3(仅限上传任务)
transferUtility.enumerateToAssignBlocks(forUploadTask: { let progressPointer = AutoreleasingUnsafeMutablePointer(&uploadProgressBlock) let completionPointer = AutoreleasingUnsafeMutablePointer (&completionBlock) progress = progressPointer completion = completionPointer } , downloadTask: nil)
但是Xcode会抛出以下错误
无法将type() - >()的值转换为预期的参数类型[...]
有人在Swift 3中工作吗?可能方法签名已经改变
编辑:
我申请了@donkon回答:
transferUtility.enumerateToAssignBlocks(forUploadTask: { (uploadTask:AWSS3TransferUtilityUploadTask, progress:AutoreleasingUnsafeMutablePointer<(@convention(block) (AWSS3TransferUtilityTask, Progress) -> Void)?>?, error: AutoreleasingUnsafeMutablePointer<(@convention(block) (AWSS3TransferUtilityUploadTask, Error?) -> Void)?>?) in let progressPointer = AutoreleasingUnsafeMutablePointer(&self.progressBlock) let completionPointer = AutoreleasingUnsafeMutablePointer (&self.completionHandler) // progress = progressPointer completion = completionPointer }, downloadTask: nil)
现在Xcode告诉进度和完成都是值,不能更改.