问题描述
我遵循此,我正在尝试Swift。
文件
对象没有 downloadUrl
财产,我不明白为什么。我查看了,并且表示此属性存在,位于至少Objective-C。但是所有其他的属性都存在于Swift中,为什么不是 downloadUrl
? 我做了一件简单的事情: p>
let file:GTLDriveFile!
file.downloadUrl
和 downloadUrl
用红色加下划线表示错误:
类型'GTLDriveFile'的值没有成员'downloadUrl'
。
这是我的代码:
private let service = GTLServiceDrive()
//解析结果并显示
func displayResultWithTicket(ticket:GTLServiceTicket,
finishedWithObject response:GTLDriveFileList,
error:NSError?){
if error = error {
showAlert(Error,message:error.localizedDescription)
return
}
var filesString =
如果let files = response .files其中!files.isEmpty {
filesString + =文件:\ n
用于文件中的文件! [GTLDriveFile] {
var fetcher:GTMSessionFetcher = service.fetcherService.fetcherWithURL(file.downloadUrl)
filesString + =\(file.name)\\\
}
}其他{
filesString =没有找到文件。
}
output.text = filesString
}
让url =https://www.googleapis.com/drive/v2/files/+ file.identifier +?alt = media
let fetcher = service.fetcherService.fetcherWithURLString(url)$ b $如果错误== nil {
print(data)
} else else {
print(error()),则返回
中的无效值({(data,error)发生:+ error!.localizedDescription)
}
})
另一个选项是在没有?alt = media的情况下调用并从元数据json中提取downloadUrl
I am following this tutorial and I'm trying to do it in Swift.
The file
object does not have a downloadUrl
property and I do not understand why. I checked the API and it says that this property exists, at least for Objective-C. But all other properties exist for Swift, so why not downloadUrl
?
I do a simple thing like:
let file: GTLDriveFile!
file.downloadUrl
and downloadUrl
get underlined in red with the error:Value of type 'GTLDriveFile' has no member 'downloadUrl'
.
Here is my code:
private let service = GTLServiceDrive()
// Parse results and display
func displayResultWithTicket(ticket : GTLServiceTicket,
finishedWithObject response : GTLDriveFileList,
error : NSError?) {
if let error = error {
showAlert("Error", message: error.localizedDescription)
return
}
var filesString = ""
if let files = response.files where !files.isEmpty {
filesString += "Files:\n"
for file in files as! [GTLDriveFile] {
var fetcher: GTMSessionFetcher = service.fetcherService.fetcherWithURL(file.downloadUrl)
filesString += "\(file.name)\n"
}
} else {
filesString = "No files found."
}
output.text = filesString
}
What I ended up doing is generating the download URL myself like this:
let url = "https://www.googleapis.com/drive/v2/files/" + file.identifier + "?alt=media"
let fetcher = service.fetcherService.fetcherWithURLString(url)
fetcher.beginFetchWithCompletionHandler({ (data, error) -> Void in
if error == nil {
print(data)
} else {
print("An error occurred: " + error!.localizedDescription)
}
})
Another option is to call without "?alt=media" and extract downloadUrl from the meta data json
这篇关于类型'GTLDriveFile'的值没有成员'downloadUrl'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!