键入' String'没有向协议确认序列类型'

时间:2016-08-11 12:47:26

标签: ios swift swift2

我想跳过使用Xcode7.3.1并转换我的代码,但是我在这里遇到了一些问题,这就是我以前在Swift1.1中使用它的方法,但是我收到了错误 - 类型'字符串'没有向协议确认序列类型'

这是我的代码: -

func makeArrayForPrimary(count:Int)
{
    let str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    for character in str //In This line error is there
    {
        var primaryDicArray = [String]()
        for var index = 0; index < self.count; ++index
        {
            var str:String
            var lowerCasestr:String

            var data = self.primaryList.objectAtIndex(index) as String
            let str1 = data
            str = str1

            let str2:String = String(character)
            if str.hasPrefix(str2)
            {
                primaryDicArray.append(str)
            }
        }

        if primaryDicArray.count > 0
        {
            sectionArrayForPrimary.append(String(character))
            self.arr1.append(primaryDicArray)
        }
    }
    self.serviceDataTableView.reloadData()
}

1 个答案:

答案 0 :(得分:0)

而不是:

for character in str

使用:

for character in str.characters