Dailen Spencer Dailen Spencer - 1 year ago 138
Swift Question

Swift: Convert UITextField input to string and split string at certain character

I am trying to convert the text inside a UITextField into a string so that I can use the method "componentsSeperatedByString(".") on the string in order to turn it into an array. But I keep receiving an error that UITextField does not have member "componentsSeperatedByString". Any advice? Thanks

import UIKit
import Parse

class ViewController: UIViewController {

override func 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) {

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


Answer Source

The username is a UITextField not String. Try this:

var username_array: [String] = username.text.componentsSeperatedByString(".")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download