Search code examples
swiftxcodeuistoryboardsegue

Error while invoking performSegue function


I could call my performSegue outside alamofire validation handler. but I want to segue after the alamofire request is succeeded

here is my code

Alamofire.request("link", method: .post, parameters: parameters!, encoding: JSONEncoding.default).responseJSON { response in
                switch response.result {
                case .success:
                    performSegue(withIdentifier: "successRegistration", sender: Any?)
                case .failure(let error):
                    print(error)
                }
            }

the problem is in the following line

performSegue(withIdentifier: "successRegistration", sender: Any?)

it shows me the following error

expected member name or constructor call after type name

and xcode gives me two fixes, one is to change Any? to Any?() which gives me another error as shown below:

cannot invoke initializer for type 'Any?' with no arguments

the other fix is to change Any? to Any?.self and this gives me another error show below:

Implicit use of 'self' in closure, use 'self.' to make capture semantics explicit

the same problem (above) occurs when I change Any? to nil

What is causing this error? (knowing that the performSegue function works fine outside Alamofire when I change Any? to nil )


Solution

  • self.performSegueWithIdentifier("successRegistration", sender: nil)
    

    try to use "self" before performSegue function.