我不明白为什么该函数不返回值!
我试图退还字典!但是没有结果!我试图在闭包内部打印结果,并且值就在那上面!但是,当我尝试从该函数返回值时,结果是空的!帮助!
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
}