仅限SwiftyDropbox列表文件夹

时间:2017-07-26 08:12:57

标签: swift dropbox-api swiftydropbox

我在我的iOS应用程序中使用SwiftyDropbox SDK,我试图仅在我的应用程序中列出文件夹,然后用户可以选择一个文件夹(而不是文件)。

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.
}

条目是>

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

我怎样才能找到这个条目是文件夹,它是否包含子文件夹?

2 个答案:

答案 0 :(得分:5)

您可以像这样在entry result.entries循环中投放每个for

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)
    }
}

答案 1 :(得分:3)

Dropbox API不提供仅列出文件夹的方法(虽然我们将其视为功能请求),因此您需要列出所有内容并过滤掉文件。

您可以FileMetadata FolderMetadata对象DeletedMetadata区分switchMetadatarecursive=true

如果您还需要子文件夹,则可以在调用shown in the README时指定SELECT cc.RefNo ,cc.Subcase ,ev.EventDate ,evt.EventCode ,ev.Amount ,previousevent.EventCode as [previous Event] ,previousevent.previousdate as [date previous event] FROM event ev JOIN EventTemplate evt ON ev.EventTemplateID = evt.ID JOIN CCase cc ON cc.ID = ev.CCaseID JOIN (SELECT MAX(ev.EventDate) as previousdate, evt.EventCode, CCaseID FROM Event ev JOIN EventTemplate evt ON ev.EventTemplateID = evt.ID WHERE (evt.EventCode LIKE 'SI%' OR evt.EventCode LIKE 'SM%') Group by CCaseID, evt.EventCode) as previousevent ON previousevent.CCaseID = cc.ID AND previousevent.previousdate < ev.EventDate