Unexpected non-void return value in void function (Swift 3)

Creign
func postUser(username: String, pass: String) -> Bool {
            Alamofire.request("https://someAPI.com/auth/login", method: .post, parameters: ["email": contact, "password": pass], encoding: URLEncoding.default, headers: ["Accept":"application/json"]).responseJSON { (response) in

                switch(response.result) {
                    case .success(let value):
                        let json = JSON(value)
                        print("JSON: \(json)")
                        print(json["data"]["result"])
                        return true
                    case .failure(let error):
                        print(error)
                        return false
                }
            }
        }
Reinier Melian

If you are calling an async method like Alamofire.request, then you need notify when this async method is over with closures

Try with this

func postUser(username: String, pass: String, finishedClosured:@escaping ((Bool)->Void))  {
            Alamofire.request("https://someAPI.com/auth/login", method: .post, parameters: ["email": contact, "password": pass], encoding: URLEncoding.default, headers: ["Accept":"application/json"]).responseJSON { (response) in

                switch(response.result) {
                    case .success(let value):
                        let json = JSON(value)
                        print("JSON: \(json)")
                        print(json["data"]["result"])
                        finishedClosured(true)
                    case .failure(let error):
                        print(error)
                        finishedClosured(false)
                }
            }
        }

Use it

 self.postUser(username: "your UserName", pass: "Your Pass") { (result) in
            if(result){
                debugPrint("All is fine")
            }else{
                debugPrint("All is wrong")
            }
        }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

unexpected non-void return value in void function in new Swift class

Unexpected non-void return value in void function

Unexpected Non-Void Return Value In Void Function (Swift 2.0)

Type No return, in function returning non-void

Swift 3: Cannot call value of non-function type '(() -> Void)?'

How to convert 'void *' return from a C function to 'UnsafeMutableRawPointer' in Swift 3?

Why does Unexpected non-void return value in void function happen?

Unexpected non-void return value in void function Swift3

Return value void * in a function

Warning 'return' with no value, in function returning non-void - What should it return?

swift Non-void function should return a value in a guard let

Restrict function return value to void

Non-void function potential lack of return

Retrieve product localised price - Unexpected non-void return value in void function

What's the return value of a non-void function missing return statement?

Unexpected non-void return value in void function - Swift 4 (Firebase, Firestore)

Should i return a value for a Future<void> Function?

Is the return command in a non-void function necessary?

What is the return value if we dont return anything from a non void return typed function in c++?[Experimental]

void function pointer return value in C

Unclear about return value of a void function in C

How to return nil object in non void function - swift 2.1?

why in this code would I be getting "Unexpected non-void return value in void function"

Class understanding: Unexpected non-void return value in void function (swift 3)

unexpected non void return value in void function

Unexpected non-void return value in void function(swift3)

Unexpected non-void return value in void function swift 4 using json serialisation

Swift NumberOfRowsInSection Unexpected non-void return value in void function

'Unexpected non-void return value in void function' in swiftui

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  3. 3

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  4. 4

    pump.io port in URL

  5. 5

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    Do Idle Snowflake Connections Use Cloud Services Credits?

  9. 9

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  10. 10

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  11. 11

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  12. 12

    Generate random UUIDv4 with Elm

  13. 13

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  14. 14

    Is it possible to Redo commits removed by GitHub Desktop's Undo on a Mac?

  15. 15

    flutter: dropdown item programmatically unselect problem

  16. 16

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  17. 17

    EXCEL: Find sum of values in one column with criteria from other column

  18. 18

    Pandas - check if dataframe has negative value in any column

  19. 19

    How to use merge windows unallocated space into Ubuntu using GParted?

  20. 20

    Make a B+ Tree concurrent thread safe

  21. 21

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

HotTag

Archive