We Want to Hear From You! What Do You Want to See on the Community? Tell us here!
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) } }
2 Replies
- Greg-DB5 years ago
Dropbox Community Moderator
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) } }
- dahunter5 years agoNew member | Level 2
Thanks so much!
About Discuss Dropbox Developer & API
Make connections with other developers814 PostsLatest Activity: 2 years ago
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If 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!