【发布时间】:2020-11-23 11:36:45
【问题描述】:
- 希望在我的项目中包含一些简单的股票数据
- 为此使用 rapidAPI
我有各种初学者错误,我无法解决。一些帮助将不胜感激。试图用谷歌搜索它并阅读苹果文档,但没有走远。这是代码部分:
import Foundation
struct StockDataManager {
let headers = [
"x-rapidapi-host": "yahoo-finance15.p.rapidapi.com",
"x-rapidapi-key": "MYAPIKEY"
]
let request = NSMutableURLRequest(url: NSURL(string: "https://yahoo-finance15.p.rapidapi.com/api/yahoo/qu/quote/AAPL/financial-data")! as URL,
cachePolicy: .useProtocolCachePolicy,
timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers
let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
if (error != nil) {
print(error)
} else {
let httpResponse = response as? HTTPURLResponse
print(httpResponse)
}
})
dataTask.resume()
}
此时我收到以下错误:
request.httpMethod = "GET"
- 一行中的连续声明必须用';'分隔
- 函数声明的参数列表中应为 '('
- 函数声明体中应为“{”
- 实例方法声明中应包含“func”关键字
- 预期声明
- “request()”的重新声明无效
这里:
dataTask.resume()
- 一行中的连续声明必须用';'分隔
- 函数声明的参数列表中应为 '('
- 函数声明体中应为“{”
- 实例方法声明中应包含“func”关键字
我很确定这是基本的理解,对于这个愚蠢的简单问题感到抱歉。提前感谢您的帮助。
【问题讨论】:
标签: swift nsurl nsmutableurlrequest