我正在尝试将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(".")
}
}
答案 0 :(得分:0)
username
是UITextField
而非String
。试试这个:
var username_array: [String] = username.text.componentsSeperatedByString(".")