如何通过完成处理程序的返回来制作函数?

时间:2019-07-02 00:30:38

标签: swift google-drive-api

我不明白为什么该函数不返回值!

我试图退还字典!但是没有结果!我试图在闭包内部打印结果,并且值就在那上面!但是,当我尝试从该函数返回值时,结果是空的!帮助!

func getAllFiles(folderID: String, service: GTLRDriveService) -> [String : String] {

        let root = "mimeType = 'image/jpeg' and trashed=false"
        let withName = "'\(folderID)'"
        let query = GTLRDriveQuery_FilesList.query()
        var result = [String : String]()

        query.corpora = "user"
        query.spaces = "drive"
        query.q = "\(withName) in parents and \(root)"
        service.executeQuery(query, completionHandler: {(ticket, files, error) in

            guard error == nil else {
                let myAlert = UIAlertController(title: "Alert!", message: error!.localizedDescription, preferredStyle: .alert)
                myAlert.show(self, sender: self)
                fatalError(error!.localizedDescription) 
            }
            if let filesList : GTLRDrive_FileList = files as? GTLRDrive_FileList {
                if let filesShow : [GTLRDrive_File] = filesList.files {

                    for i in filesShow {
                    result.updateValue(i.identifier!, forKey: i.name!)
            // HERE, I GOT RESULT!
                    print(result)
                    }     
                }
            }
        })
        print(result)
  // HERE NOTHING!
        return result
    } 

0 个答案:

没有答案