swiftdropbox-apiswiftydropbox

SwiftyDropbox list folders only


Im using SwiftyDropbox SDK in my iOS application, im trying to list folders only in my app then user can choose a folder (not a file).

in ViewController => viewDidLoad

override func viewDidLoad() {
    super.viewDidLoad()

    guard let dropboxClient = DropboxClientsManager.authorizedClient else{
        return
    }

    let listFolders = dropboxClient.files.listFolder(path: "")
    listFolders.response{ response, error in
        guard let result = response else{
            return
        }

        for entry in result.entries{
            print(entry)
        }
    }
    // Do any additional setup after loading the view, typically from a nib.
}

entry is >

  { 
      id = "id:0GMPvYwuVEAAAAAAAAAABw";
      name = "Folder A";
      "path_display" = "/Folder A";
      "path_lower" = "/folder a";
  }

how can i find this entry is folder and it contains sub folder or not?


Solution

  • You can cast each entry inside of your result.entries for loop like this

    override func viewDidLoad() {
        super.viewDidLoad()
    
        guard let dropboxClient = DropboxClientsManager.authorizedClient else{
            return
        }
    
        for entry in result.entries{
           guard let file = entry as? Files.FolderMetadata else{
             return
           }
    
           // only folders
           print(entry)
    
           // *********  or 
           gurad let entry is Files.FolderMetadata else{
             return
           }
    
           // only folders
           print(entry)
        }
    }