Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 3-有没有办法强制对对象调用方法?_Swift_Methods_Swift3_Call - Fatal编程技术网

Swift 3-有没有办法强制对对象调用方法?

Swift 3-有没有办法强制对对象调用方法?,swift,methods,swift3,call,Swift,Methods,Swift3,Call,我做了一个简单的API管理器。执行请求的方法是: ApiManager .get("method_name") .parameters(["xxx" : "yyy"]) .requireAuth(true) .request(success: success, failure: failure) 其中: .get(“people/1/”)-此静态方法返回ApiManager对象 .request(成功:成功,失败:失败)-此方法启动请求 我想知道是否有可能在Swift 3中强制调用这两种方法?

我做了一个简单的API管理器。执行请求的方法是:

ApiManager
.get("method_name")
.parameters(["xxx" : "yyy"])
.requireAuth(true)
.request(success: success, failure: failure)
其中:

.get(“people/1/”)
-此静态方法返回ApiManager对象

.request(成功:成功,失败:失败)
-此方法启动请求

我想知道是否有可能在Swift 3中强制调用这两种方法? 有没有办法防止调用ApiManager的初始值设定项

编辑

谢谢你的回答。 我编辑了我的类,现在API请求看起来:

ApiManager(method: .get, action: "people/1/")
.parameters(["xxx" : "yyy"])
.requireAuth(true)
.request(success: success, failure: failure)
我将我的初始信息保密给:

private init() {}

似乎您的函数是类函数,并且没有调用ApiManager的初始化器。(应该是
apimager()
)。你说的“强制呼叫”是什么意思?他们没有被调用吗?实际上我的method.get(“xxx”)是一个静态方法,里面有init,它返回了ApiManager的对象。“强制调用”-我的意思是我想通知程序员他必须调用method.get()。无论如何,谢谢你的回答。
class ApiManager {
    private init(){

    }
}