Daniel ORTIZ
Daniel ORTIZ

Reputation: 2520

Know if error exist or not if Swift function

Sometimes the function has this structure:

func prueba(................, error: Error?){
    //Code here

    //How I can validate if error really exist?
}

If I use if to make error!=nil, always is not true but the error don't exist.

Upvotes: 0

Views: 59

Answers (1)

rmaddy
rmaddy

Reputation: 318824

For functions that actually have an optional Error parameter, you can do something like this:

if let error = error {
    // there is an error, handle as needed
    print("Error: \(error)")
} else {
    // no error
}

Upvotes: 3

Related Questions