0

我正在连接到 Dropbox 并通过函数调用列出目录的内容。我想在完成此函数调用时返回数组。

我不太明白为什么下面的代码不处理返回。(我试图不使用公共变量)。我认为这与关闭有关?

  static func dropboxWorkoutList() -> [String] {
    let client  = DropboxClientsManager.authorizedClient
    var files: [String] = []
    
    client?.files.listFolder(path: "/workouts")
      .response { response, error in
        if let result = response {
          for entry in result.entries {
            if let file = entry as? Files.FileMetadata {
              let ext = (file.name as NSString).pathExtension
              
              switch ext {
              case "txt":
                //  print("filename:\(file.name) ext:\(ext) path:\(file.pathLower)")
                files.append(file.pathLower!)
                
              default:
                continue
              }
            }
          }
          files = files.sorted(by: { $0 < $1 } )
          // code executes until here. prints out the content 
          // but doesn't "return files array"
          print("Contents of Workout Folder:\(files)") 
        } else if let error = error {
          print(error)
        }
      }
    print("ASA")
    return files // returns []
  }
4

0 回答 0