本文介绍了无法使用类型为swift 2.0的参数列表调用reduce的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我将swift 1.2升级到swift 2.0时,会发生以下错误
When i upgrade swift 1.2 to swift 2.0 following error occurs
无法使用类型为
cannot invoke reduce with an argument list of type
这是代码
let escaped = reduce(string, "") { string, character in string + (character == mark ? "\(mark)\(mark)" : "\(character)")能帮我解决这个问题吗
推荐答案reduce()是用于数组之类的集合的方法,因此您必须在可以使用的characters属性访问的字符列表中调用它字符串,而不是整个字符串本身:
reduce() is a method for collections such as arrays so you have to call it on the list of the characters you can access using the characters property of the string, not on the whole string itself:
let escaped = string.characters.reduce("") { string, character in string + (character == mark ? "\(mark)\(mark)" : "\(character)") }更多推荐
无法使用类型为swift 2.0的参数列表调用reduce
发布评论