接受函数的回调作为参数

时间:2016-02-10 08:13:12

标签: ios swift snapkit

我正在使用SnapKit,我试图将闭包作为参数传递给我的函数,该函数调用下面的snp_makeConstaints,

func drawView(view: UIView, callback: (() -> Void)!) {
    self.addSubview(view)
    view.snp_makeConstraints(closure: callback)
}

我收到以下错误,

../example.swift:57:43: Cannot convert value of type '(() -> Void)!' to expected argument type '@noescape (make: ConstraintMaker) -> Void'

因此我添加了(make: ConstaintMaker) -> Void

导致以下错误, Use of undeclared type 'ConstraintMaker'

我不明白@noescape是什么以及它为什么说ConstraintMaker未声明。

1 个答案:

答案 0 :(得分:0)

在您遇到问题的swift文件的顶部添加import SnapKit

相关问题