我收到以下错误,“类型‘配置’的值没有成员‘配置’”。基本上,我正在尝试与列出的 API 建立连接。作为参考,我正在运行 Siesta 和 SwiftyJSON,这两个对我来说都是新的。任何帮助都会很棒。
import Foundation
import Siesta
import SwiftyJSON
let Pokeapi = _Pokeapi()
class _Pokeapi: Service {
public init() {
super.init(baseURL: "https://pokeapi.co/api/v2")
self.configure {
$0.config.pipeline[.parsing].add(SwiftyJSONTransformer, contentTypes: ["*/json"])
$0.config.expirationTime = 3600
}
}
}
public let SwiftyJSONTransformer =
ResponseContentTransformer
{ JSON($0.content as AnyObject) }
所以你得到的错误是因为你的闭包中的 $0 指的是一个 Configuration 类型的变量,它没有一个名为 config 的成员。相反,也许你想写:
self.configure { config in
config.pipeline[.parsing].add(SwiftyJSONTransformer, contentTypes: ["*/json"])
config.expirationTime = 3600
}
请注意,您也可以这样做
self.configure {
$0.pipeline[.parsing].add(SwiftyJSONTransformer, contentTypes: ["*/json"])
$0.expirationTime = 3600
}
但是如果你命名闭包变量,它会产生更好的可读代码
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句