首页 > 编程语言 > 详细

Swift 2.0 : 'enumerate' is unavailable: call the 'enumerate()' method on the sequence

时间:2016-01-18 22:45:27      阅读:200      评论:0      收藏:0      [点我收藏+]

很多全局函数已被Protocol扩展方法,一个新的功能取代 Swift 2,所以 enumerate() 现在是扩展方法为SequenceType :

extension SequenceType {
    func enumerate() -> EnumerateSequence<Self>
}

  用作

let ztList = [ "foo", "bar" ]
for (index, string) in
ztList.enumerate() {
   print(string)
}

  String并不再符合 SequenceType ,您必须使用 characters 属性来获取的 Unicode 字符的集合。此外, 

  count()是一种Protocol扩展方法的   CollectionType 而不是一个全局函数:

let myString = "foo"
let stringLength = myString.characters.count
print(stringLength)

Swift 2.0 : 'enumerate' is unavailable: call the 'enumerate()' method on the sequence

原文:http://www.cnblogs.com/xilanglang/p/5140546.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!