Sunday 15 August 2010

Swift - UITextField.text - error: string is not convertible to () -


I am assuming a value from a UITextField object and I have difficulty using the UITextField.text property as a string Has been there. I am trying to pass the value to clear the value and connect the return value to a variable, but I get the error 'string' to '()' and 'vice versa. Even if I comment on string eccentricity and return the value passed to the function, I get a single problem. Am I doing wrong here?

Import UIKit Class ViewController: UIViewController {@IBOutlet Weak City: Name: UITextField! Var city: string? = Clean (cityName.text) // '()' is not variable for 'string' if city! Clear the function (str: string) {var trimmedStr = str.stringByTrimmingCharactersInSet (NSCharacterSet.whitespaceCharacterSet ()) var cleanedtrtr = str.stringByReplacingOccurrencesOfString ("", with string: "-") Returns clean STR / 'string' is not variable for '()' // return str, the same error is generated)

You have not set the return type for your clean function. It should look;

  Clear Function (str: string) - & gt; String  

No comments:

Post a Comment