我更新到swift 3.0,我得到这两个错误请帮助。下面是代码和图片
我在self.blockfinish
收到错误var blockFinish: ((_ 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.dismissViewControllerAnimated(true, completion: { () -> Void in
self.blockFinish(selectedTags: selected, unSelectedTags: unSelected)
})
}
这里我在let中遇到错误(“addTagView.textEdit.text.stringByTrimmingCharactersInSet(spaceSet)”)
func createNewTag() {
let spaceSet = NSCharacterSet.whitespaces
let contentTag = addTagView.textEdit.text.stringByTrimmingCharactersInSet(spaceSet)
if strlen(contentTag) > 0 {
let newTag = Tag(isSelected: false, isLocked: false, textContent: contentTag)
tags.insert(newTag, atIndex: tags.count)
collectionTag.reloadData()
}
cancelEditTag()
}
答案 0 :(得分:0)
Swift 3.0中字符串修剪方法的签名已更改。 Here is the new method:
func trimmingCharacters(in set: CharacterSet) -> String
所以而不是:
let contentTag = addTagView.textEdit.text.stringByTrimmingCharactersInSet(spaceSet)
你会这样做:
let contentTag = addTagView.textEdit.text.trimmingCharacters(in: spaceSet)
修改强>
blockFinish
在呼叫站点没有参数名称。
替换:
self.blockFinish(selectedTags: selected, unSelectedTags: unSelected)
使用:
self.blockFinish(selected, unSelected)