在服务器端swift的Vapor框架中,我想回复一个请求,其中包含我从第三方API获得的信息.例如,我收到一个询问城市温度的获取请求,我想连接到雅虎是否API获取温度然后将其发回.我需要下载像Alamofire这样的套餐吗?或者在Vapor中是否有内置方法可以这样做?
我有这个协议:
protocol Container: class where Self: UIViewController {
var containerView: UIView! { get }
var currentChild: UIViewController? { get set }
func remove(child viewController: UIViewController)
func add(child viewController: UIViewController)
func replaceCurrentViewController(with newChild: UIViewController)
}
Run Code Online (Sandbox Code Playgroud)
我面临的问题是它显示以下警告
冗余约束“Self”:“AnyObject”
这是因为我同时使用class & where Self: UIViewController,但我需要两者!原因在于我的协议扩展(见下文),我使用 UIViewController 方法,如果我删除class,我的扩展会显示一个错误,要求添加mutating,它不应该有,因为它是一个仅限类的协议。
extension Container {
func remove(child viewController: UIViewController) {
viewController.beginAppearanceTransition(false, animated: true)
viewController.willMove(toParent: nil)
viewController.removeFromParent()
viewController.view.removeFromSuperview()
viewController.endAppearanceTransition()
currentChild = nil
}
func add(child viewController: UIViewController) {
viewController.beginAppearanceTransition(true, animated: true)
addChild(viewController)
viewController.didMove(toParent: self) …Run Code Online (Sandbox Code Playgroud)