Discuss Dropbox Developer & API
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) } }
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) } }
Thanks so much!
Hi there!
If you need more help you can view your support options (expected response time for a 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!