Swift Block value error

2019-03-02 06:39发布

I keep getting a finish block error in swift. The error is:

Cannot call value of non-function type'((Array,Array)->())!

There's an image of the error below as well. Here's the code:

var blockFinih: ((_ selectedTags: Array<Tag>, _ unSelectedTags: Array<Tag>) -> ())!

func finishTagController() {
    var selected: Array<Tag> = Array()
    var unSelected: Array<Tag> = Array()

    for currentTag in tags {
        if currentTag.isSelected {
            selected.append(currentTag)
        }
        else {
            unSelected.append(currentTag)
        }
    }
    self.dismiss(animated: true, completion: { () -> Void in
        self.blockFinih(selectedTags: selected, unSelectedTags: unSelected)
    })
}

标签: swift swift3
1条回答
干净又极端
2楼-- · 2019-03-02 06:58

Don't specify the argument labels when you call blockFinih. You've defined it to have no argument labels. The parameters selectedTags and unSelectedTags can only be used inside the function, not by the caller.

Change:

self.blockFinih(selectedTags: selected, unSelectedTags: unSelected)

to:

self.blockFinih(selected, unSelected)
查看更多
登录 后发表回答