Swift:将UITextField输入转换为字符串并将字符串拆分为特定字符

时间:2015-06-18 01:08:42

标签: ios string swift

我正在尝试将UITextField中的文本转换为字符串,以便我可以在字符串上使用方法" componentsSeperatedByString("。")以便将其转换为数组。但是我一直收到UITextField没有成员" componentsSeperatedByString"的错误。有什么建议?感谢

import UIKit
import Parse

class ViewController: UIViewController {


    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }




    @IBOutlet weak var username: UITextField!



    @IBOutlet weak var password: UITextField!



    //Login function. Drag Down keyboard after clicking login
    @IBAction func Login(sender: AnyObject) {
        username.resignFirstResponder()
        password.resignFirstResponder()

        var username_array: [String] = username.componentsSeperatedByString(".")


}
}

1 个答案:

答案 0 :(得分:0)

usernameUITextField而非String。试试这个:

var username_array: [String] = username.text.componentsSeperatedByString(".")