Q:

Login with Enums

I'm trying to create a simple way of logging in users, however it does not seem to work at the moment. I keep getting and error with a missing argument in .Email(LoginUser)
enum LoginProvider {
    case Facebook
    case Email(String, String)

    func login() {
        switch self {
        case .Email(LoginUser) where LoginUser.isValid():
            break

        case .Facebook:

            break
        }
    }

}

struct LoginUser {
    let email: String
    let password: String
    func isValid() -> Bool {
        return email != "" && password != ""
    }

}

A:

I checked your code on playground and made some changes that would fix the errors. Which are 1. case Email(LoginUser) and 2. missing default: case in LoginProvider's login().
You make these changes and I believe it would fix the issue.
Here is the working code on playgrund.
struct LoginUser {

    let email: String
    let password: String

    func isValid() -> Bool {
        return email.characters.count > 0 && password.characters.count > 0
    }
}

enum LoginProvider {

    case Facebook
    case Email(LoginUser)

    func login() {

        switch self {

        case .Email(let user) where user.isValid():
            print("Login with email")
            break

        case .Facebook:
            print("Login with Facebook")
            break

        default:
            break
        }

    }
}

let provider: LoginProvider = LoginProvider.Email(LoginUser(email: "email", password: "pass"))
provider.login()

