Ios Swift:将UITextField输入转换为字符串,并在特定字符处拆分字符串
我正在尝试将UITextField中的文本转换为字符串,以便对字符串使用方法“ComponentsOperationedByString(“.”),以便将其转换为数组。但我一直收到一个错误,即UITextField没有成员“ComponentsOperationedByString”。有什么建议吗?谢谢Ios Swift:将UITextField输入转换为字符串,并在特定字符处拆分字符串,ios,string,swift,Ios,String,Swift,我正在尝试将UITextField中的文本转换为字符串,以便对字符串使用方法“ComponentsOperationedByString(“.”),以便将其转换为数组。但我一直收到一个错误,即UITextField没有成员“ComponentsOperationedByString”。有什么建议吗?谢谢 import UIKit import Parse class ViewController: UIViewController { override func didReceiv
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(".")
}
}
username
是一个UITextField
而不是String
。请尝试以下操作:
var username_array: [String] = username.text.componentsSeperatedByString(".")
用户名是一个文本字段。它不应该是username.text,然后调用username_text.componentsOperationedByString(“.”)