cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Share your feedback on the Document Scanning Experience in the Dropbox App right here.

Discuss Dropbox Developer & API

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how to extract name and pathdisplay from swiftydropbox searchv2 results

how to extract name and pathdisplay from swiftydropbox searchv2 results

dahunter
New member | Level 2
Go to solution

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?

 

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

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

View solution in original post

2 Replies 2

Greg-DB
Dropbox Staff
Go to solution

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

dahunter
New member | Level 2
Go to solution

Thanks so much!

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    dahunter New member | Level 2
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?