小编nai*_*aif的帖子

如何在Vapor中发出连接第三方API的请求?

在服务器端swift的Vapor框架中,我想回复一个请求,其中包含我从第三方API获得的信息.例如,我收到一个询问城市温度的​​获取请求,我想连接到雅虎是否API获取温度然后将其发回.我需要下载像Alamofire这样的套餐吗?或者在Vapor中是否有内置方法可以这样做?

swift3 vapor

9
推荐指数
1
解决办法
1749
查看次数

冗余约束“Self”:“AnyObject”

我有这个协议:

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)

uiviewcontroller ios swift

5
推荐指数
1
解决办法
1545
查看次数

标签 统计

ios ×1

swift ×1

swift3 ×1

uiviewcontroller ×1

vapor ×1