xcode 显示错误 - 'appendingPathComponent' 不可用:改用 URL 上的 appendingPathComponent
xcode showing error - 'appendingPathComponent' is unavailable: Use appendingPathComponent on URL instead
我知道之前有人问过这个问题,但在我的情况下如何解决这个问题 -
import Stripe
class MyAPIClient: NSObject, STPCustomerEphemeralKeyProvider {
let baseURL = "https://api.stripe.com"
func createCustomerKey(withAPIVersion apiVersion: String, completion: @escaping STPJSONResponseCompletionBlock) {
let url = self.baseURL.appendingPathComponent("ephemeral_keys") /*1st error - 'appendingPathComponent' is unavailable: Use appendingPathComponent on URL instead.*/
var urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false)! /*2nd error - Cannot convert value of type 'String' to expected argument type 'URL'*/
urlComponents.queryItems = [URLQueryItem(name: "api_version", value: apiVersion)]
var request = URLRequest(url: urlComponents.url!)
request.httpMethod = "POST"
let task = URLSession.shared.dataTask(with: request, completionHandler: { (data, response, error) in
guard let response = response as? HTTPURLResponse,
response.statusCode == 200,
let data = data,
let json = ((try? JSONSerialization.jsonObject(with: data, options: []) as? [String : Any]) as [String : Any]??) else {
completion(nil, error)
return
}
completion(json, nil)
})
task.resume()
}
}
i) 我正在使用
a)swift
b)firestore
c) nodejs - 我应该使用其他东西而不是 node js 吗?
此外,我还应该做哪些其他修改?欢迎所有其他建议。
Apple 已经从 String
中删除了很长时间的路径修改 API。
您必须创建一个 URL,这就是错误的提示
let baseURL = URL(string: "https://api.stripe.com")!
我知道之前有人问过这个问题,但在我的情况下如何解决这个问题 -
import Stripe
class MyAPIClient: NSObject, STPCustomerEphemeralKeyProvider {
let baseURL = "https://api.stripe.com"
func createCustomerKey(withAPIVersion apiVersion: String, completion: @escaping STPJSONResponseCompletionBlock) {
let url = self.baseURL.appendingPathComponent("ephemeral_keys") /*1st error - 'appendingPathComponent' is unavailable: Use appendingPathComponent on URL instead.*/
var urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false)! /*2nd error - Cannot convert value of type 'String' to expected argument type 'URL'*/
urlComponents.queryItems = [URLQueryItem(name: "api_version", value: apiVersion)]
var request = URLRequest(url: urlComponents.url!)
request.httpMethod = "POST"
let task = URLSession.shared.dataTask(with: request, completionHandler: { (data, response, error) in
guard let response = response as? HTTPURLResponse,
response.statusCode == 200,
let data = data,
let json = ((try? JSONSerialization.jsonObject(with: data, options: []) as? [String : Any]) as [String : Any]??) else {
completion(nil, error)
return
}
completion(json, nil)
})
task.resume()
}
}
i) 我正在使用
a)swift
b)firestore
c) nodejs - 我应该使用其他东西而不是 node js 吗?
此外,我还应该做哪些其他修改?欢迎所有其他建议。
Apple 已经从 String
中删除了很长时间的路径修改 API。
您必须创建一个 URL,这就是错误的提示
let baseURL = URL(string: "https://api.stripe.com")!