“[String]”没有名为 'text' Swift 的成员

'[String]' does not have a member named 'text' Swift

我已经尝试解决这个问题一段时间了,但还没有找到任何解决方案。 '[String]' does not have a member named 'text'let c:Int? = conversion.text.toInt()。我知道这与字符串是浮点数有关。解决办法是什么?

 @IBOutlet var pickerView1: UIPickerView!

        @IBOutlet var textField1: UITextField!
        @IBOutlet weak var enterUnits: UITextField!
        @IBOutlet var answerConversion: UITextField!
        var measurements = ["m to feet","cm to inches", "mm to inches"]
        var conversion = ["3.12","4.54","5.23"]    

选择器视图

    func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)  {
            if pickerView.tag == 0 {

                let a:Int? = enterUnits.text.toInt()
                let c:Int? = conversion.text.toInt()

                let answer = (a!) * (c!)
                textField1.text = measurements[row]
                answerConversion.text = conversion[row]
                answerConversion.text = "\(answer)"

                }

可以声明Double数组而不是String

 let conversion = [3.12,4.54,5.23] 

并且在 pickerView 中你可以访问 like

let c = conversion[row]

[String] 没有 属性 文本,这就是您收到错误的原因。在将其转换为 int 之前,您需要使用索引调用 [String]

示例:

myStringArray[myIndex].toInt()