NSObject没有名为startIndex的成员

时间:2015-05-23 13:43:07

标签: ios swift xcode6.3

@IBAction func logEmButn(sender: AnyObject) {
    let clonCountrLableItem = clonCountLable.text!
    let baclCounterLableItem = baclCountLable.text!
    let ironCountLableItem = ironCountLable.text!
    let gymCountLableItem = gymCountLable.text!
    let asp2CountLableItem = asp2CountLable.text!
    let fiveHtpLableItem = fiveHtpLable.text!


    let selectedLables = [clonCountLable, baclCountLable, ironCountLable, gymCountLable, asp2CountLable, fiveHtpLable]

    for selectedLable in selectedLables {
        if selectedLable != "0 s" {

            println("You took \(selectedLable[selectedLable.startIndex])")

今天早些时候在一个类似的"项目,现在它给出了错误

  

' NSObject的'没有名为' startIndex'

的成员

所以,我试过了:

println("You took \(selectedLable[selectedLable.description]) \(keyOfselectedLables)")

给出了类似的错误,但以......命名'下标'

结尾

也尝试过:

            let lable = "rick"
            for index in indices(lable) {
                print("\(lable[index])")

            }

在运行时给出错误:无法转换类型' UILable' (0x199943e30)到' NSString' (0x198fb2768)。

2 个答案:

答案 0 :(得分:1)

参见下面的代码,selectedLables是UILabel的数组

let selectedLables = [clonCountLable, baclCountLable, ironCountLable, gymCountLable, asp2CountLable, fiveHtpLable]

但是在if语句中,您将类型为UILabel的selectedLable与字符串常量等同。

for selectedLable in selectedLables {
    if selectedLable != "0 s"

由于selectedLable不是字符串类型,因此它没有startIndex属性或索引。

所以我认为数组应该是

let selectedLables = [baclCounterLableItem, ironCountLableItem, gymCountLableItem, asp2CountLableItem, fiveHtpLableItem]

答案 1 :(得分:0)

Nitheesh George钉了它。 (我在这里看到的最后一个答案。)很抱歉,如果我搞砸了这里的流程,那就完全没了。