Swift - Error 'Expected ',' Separator' and 'Expected Expression in List of Expressions'

Swift - Error 'Expected ',' separator' and 'Expected expression in list of expressions'

Update the Xcode to 7.3 The new #selector syntax will only work in Xcode 7.3 (or newer)

Swift - Expected expression in list of expressions

You are using external parameter name for a parameter when calling the function, but the external parameter is not defined in your function declaration. Simply use it this way.

submitLacunaRequest(module: "empire", "login", ["myuserid", "mypassword", "mykey"]) {

Swift Expected Expression in list of Expression Error

Error 1: Non-closed parantheses

You're missing a closing paranthesis in the first if statement of the RegisterButtonTapped function:

if (((userFullName!.isEmpty || userEmail!.isEmpty 
|| userPassword!.isEmpty || userRepeatPassword.isEmpty)) {

// Display alert message
displayMyAlertMessage("All fields are required")

return
}

Three left pranthesis ((( finished by only two right ones )). I this case, you really need no set of parantheses at all, but could save one set for readability:

if (userFullName!.isEmpty || userEmail!.isEmpty
|| userPassword!.isEmpty || userRepeatPassword.isEmpty) {

// Display alert message
displayMyAlertMessage("All fields are required")

return
}

Error 2: trying to include a function declaration within another function

(As pointed out by Duy Tran)

The function displayAlertMessage(...) is positioned within the function RegisterButtonTapped. Functions may only exists as methods directly in a class/structure etc (or as a global non-class owned function e.g. in a playground).

Hence, you should make sure the function displayAlertMessage(...) is placed outside the body of function RegisterButtonTapped.

General remarks

You should avoid "forced unwrappings" of optional variables. E.g. userFullName!.isEmpty will lead to a runtime exception in case the optional immutable userFullName has valuenil`. You should read up on optionals, optional binding, and so on.

Also note that you needn't put semi-colons ; after lines in Swift. However you won't get an error for doing so:

  • [swift-evolution] Proposal to remove semicolons

How can you use a conditional statement in a swift method

You need to add a space before the ? operator. Without the space the compiler mistok it for an optional.

.padding(ButtonShape == "Circle" ? 60:30)

Swift 2: Selector in UIPinchGestureRecognizer: How to access func from another class

As can be seen in the comments above, the Xcode version is 7.2 and the #selector syntax was introduced in Xcode 7.3 and therefore not available here. This just means that you should be able to use the "old" Selector syntax.

The difference is that you just give pass a strings to the Selector with the name of your function and then a : for each of the parameters your function requires. You require one parameter (the recognizer) so in your case the string looks like this:

"changeScale:"

So you'd use:

Selector("changeScale:")

And you end up with:

    @IBOutlet weak var faceView: FaceView! {
didSet {
faceView.addGestureRecognizer(UIPinchGestureRecognizer(target: faceView, action: Selector("changeScale:")))
}
}

As you can see, this is error prone...one typo and kaboom! Which is why the new #selector syntax is a fine improvement...sorry...not trying to rub it in.

Hope this helps you.



Related Topics



Leave a reply



Submit