Dailen Spencer Dailen Spencer - 7 months ago 37
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(".")



The username is a UITextField not String. Try this:

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