无法使用类型为swift 2.0的参数列表调用reduce

编程入门 行业动态 更新时间:2024-10-28 01:12:19
本文介绍了无法使用类型为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

本文发布于:2023-11-26 16:35:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634396.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   类型   列表   swift   reduce

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!