The App Lady
The App Lady

Reputation: 53

migrated to swift 3 now getting error "argument labels '(_:)' do not match any available overloads

i've searched and read many topics that seem to have this same issue but I am unable to find any examples similar to mine. I just converted an existing project from swift 2.x (can't remember which version) to Xcode8/swift 3. The code is live in the app store so clearly was working before.

Now I'm getting the following error on what seems to be a very straightforward variable initializer statement. Please see my code below:

//GLOBAL VARIABLES - NEW-------------------------------------

var userEmail = NSString()
var userName = NSString()
var userPassword = NSString()
var userNamePass = NSString()

class ViewController: UIViewController, UITextFieldDelegate {

 @IBOutlet weak var loginUserName: UITextField!
 @IBOutlet weak var loginPassword: UITextField!


 @IBAction func loginButton(_ sender: AnyObject) {

    userName = NSString(loginUserName.text)  //throws error "argument labels '(_:)' do not match any available overloads
    userPassword = NSString(loginPassword.text)  //throws error "argument labels '(_:)' do not match any available overloads
    userNamePass = NSString("\(userName.uppercased)\(userPassword.uppercased)")   //throws error "argument labels '(_:)' do not match any available overloads


//other code in the login function

} //end login function

Upvotes: 1

Views: 398

Answers (3)

vadian
vadian

Reputation: 285069

There is a major change in Swift 3

  • It's required that all methods / functions provide a label for the first parameter. It's possible to suppress that rule by the underscore character but Apple changed all relevant methods to conform to that rule. So you have to write

    userName = NSString(string:loginUserName.text) 
    

The other issue occurs because uppercased has been changed to uppercased()


Why do you create a String from something which is a String anyway?

By the way, this is Swift. Use String rather than NSString.

var userEmail = ""
var userName = ""
var userPassword = ""
var userNamePass = ""

userName = loginUserName.text ?? "" 
userPassword = loginPassword.text ?? ""
userNamePass = userName.uppercased() + userPassword.uppercased()

Upvotes: 2

ataboo
ataboo

Reputation: 817

Try using "string:" inside the initializer.

userName = NSString(string: loginPassword.text)

Also if loginPassword.text is optional it may need to be unwrapped.

Upvotes: 0

nbloqs
nbloqs

Reputation: 3282

Try adding the "string:" argument label to all the NSString initializer calls. For example, the following code works on a Playgrounds (XCode 8 GM with Swift 3):

let userName = NSString(string: "hello")
print(userName)

Upvotes: 0

Related Questions