ios - Swift:将 UITextField 输入转换为字符串并在特定字符处分割字符串

标签 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(".")


}
}

最佳答案

用户名是一个UITextField而不是String。试试这个:

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

关于ios - Swift:将 UITextField 输入转换为字符串并在特定字符处分割字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30904957/

相关文章:

ios - Swift 在运行时获取 `Scheme Name or Swift Compiler - Custome Flags` 值

ios - 初始化(编码器:) has not Implement

ios - 解析 JSON 文件

ios - 如何获取系统 UITableVIewCell 的详细标签的文本颜色?

c# 从 sql 2005 返回一个字符串

ios - 如何在网站内容更改时发送推送通知

ios - iPhone 和桌面应用程序中带有角标(Badge)的 APNS

oracle - 从 Oracle 的给定位置删除一个字符

ios - 如何将 .cgi URL 中的参数收集到 iOS objC 中的多个字符串中?

swift - 如何在 Swift 中修复 "Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value"