【发布时间】:2017-02-24 00:41:58
【问题描述】:
我制作了简单的 API 管理器。请求的方式是:
ApiManager
.get("method_name")
.parameters(["xxx" : "yyy"])
.requireAuth(true)
.request(success: success, failure: failure)
地点:
.get("people/1/") - 这个静态方法返回 ApiManager 对象
.request(success: success, failure: failure) - 这个方法启动请求
我想知道是否可以在 Swift 3 中强制调用这两个方法? 有什么方法可以防止调用 ApiManager 的初始化程序?
编辑
感谢您的回答。 我编辑了我的课程,现在 API 请求看起来是:
ApiManager(method: .get, action: "people/1/")
.parameters(["xxx" : "yyy"])
.requireAuth(true)
.request(success: success, failure: failure)
我将我的初始化设置为私有:
private init() {}
【问题讨论】:
-
看来你的函数是类函数,没有调用ApiManager的初始化器。 (应该是
ApiManager())。 “强制呼叫”是什么意思?他们没有接到电话吗? -
其实我的方法 .get("xxx") 是静态方法,里面有init,它返回ApiManager的对象。 “强制调用” - 我的意思是我想通知程序员他必须调用方法 .get()。不管怎样,谢谢你的回答。