前提・実現したいこと
期待する結果としては
uploadAction(fileName)、search関数、その結果をもとにself.uploadを処理して次の繰り返しをpictureDicの要素数実行して欲しいのですが
現状は
uploadAction(fileName)、search関数、2回めのuploadAction(fileName)、search関数 ・・・(pictureDicの要素数繰り返す)、uploadFile関数内のif let ID = folderID以降の処理がおこなわれてself.upload処理をpictureDicの要素数繰り返してしまいます。
発生している問題・
@IBAction func finishButtonClick(_ sender: Any) { for (fileName, UIimage) in pictureDic{ saveImageToDocumentLocal(name: fileName, image: UIimage) sleep(3) uploadAction(fileName) } let nextViewController = finishViewController() UIApplication.shared.keyWindow?.rootViewController = nextViewController UIApplication.shared.keyWindow?.rootViewController?.dismiss(animated: false, completion: nil) } func uploadAction(_ file: String) { print(file) if let documentsDir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last { let testFilePath = documentsDir.appendingPathComponent(file).path drive?.uploadFile("20200204", filePath: testFilePath, MIMEType: "image/png") { (fileID, error) in print("Upload file ID: (fileID); Error: (error?.localizedDescription)") } } }
public func uploadFile(_ folderName: String, filePath: String, MIMEType: String, onCompleted: ((String?, Error?) -> ())?) { search(folderName) { (folderID, error) in if let ID = folderID { self.upload(ID, path: filePath, MIMEType: MIMEType, onCompleted: onCompleted) } else { self.createFolder(folderName, onCompleted: { (folderID, error) in guard let ID = folderID else { onCompleted?(nil, error) return } self.upload(ID, path: filePath, MIMEType: MIMEType, onCompleted: onCompleted) }) } } } public func search(_ fileName: String, onCompleted: @escaping (String?, Error?) -> ()) { let query = GTLRDriveQuery_FilesList.query() query.pageSize = 1 query.q = "name contains '(fileName)'" service.executeQuery(query) { (ticket, results, error) in onCompleted((results as? GTLRDrive_FileList)?.files?.first?.identifier, error) print("search ID: (String(describing: results)); Error: (String(describing: error))") } }
補足情報(FW/ツールのバージョンなど)
Xcode10.3
Swift4.2
あなたの回答
tips
プレビュー