You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
dahunter
5 years agoNew member | Level 2
how to extract name and pathdisplay from swiftydropbox searchv2 results
I have an app in which I was using the SwiftyDropbox function
client.files.search
and now I'm upgrading to the new
client.files.searchV2
However, the results have also changed structure (to Files.MetadataV2). Where I used to get my results with the following
let match = matches[0] // Matches is the array of Files.Metadata let fileName = match.metadata.name let filePath = match.metadata.pathDisplay
now metadata contains none of these fields. What's the process to get them?
With the new method, you can access the metadata like this:
client.files.searchV2(query: query).response { response, error in if let response = response { for entry in response.matches { switch entry.metadata { case .metadata(let metadata): switch metadata { case let fileMetadata as Files.FileMetadata: print("File name: \(fileMetadata.name)") print("File display path: \(fileMetadata.pathDisplay ?? "")") case let folderMetadata as Files.FolderMetadata: print("Folder name: \(folderMetadata.name)") print("Folder display path: \(folderMetadata.pathDisplay ?? "")") case let deletedMetadata as Files.DeletedMetadata: print("Deleted entry name: \(deletedMetadata.name)") default: print("unknown metadata type") } default: print("unknown entry type") } print("") } } else if let error = error { print(error) } }
- Greg-DBDropbox Staff
With the new method, you can access the metadata like this:
client.files.searchV2(query: query).response { response, error in if let response = response { for entry in response.matches { switch entry.metadata { case .metadata(let metadata): switch metadata { case let fileMetadata as Files.FileMetadata: print("File name: \(fileMetadata.name)") print("File display path: \(fileMetadata.pathDisplay ?? "")") case let folderMetadata as Files.FolderMetadata: print("Folder name: \(folderMetadata.name)") print("Folder display path: \(folderMetadata.pathDisplay ?? "")") case let deletedMetadata as Files.DeletedMetadata: print("Deleted entry name: \(deletedMetadata.name)") default: print("unknown metadata type") } default: print("unknown entry type") } print("") } } else if let error = error { print(error) } }
- dahunterNew member | Level 2
Thanks so much!
About Discuss Dropbox Developer & API
Make connections with other developers
797 PostsLatest Activity: 21 hours agoIf you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!