The dictionary does not convert to Void

Hi guys, I was looking for a network without much luck, but I'm trying to get around the asynchronous nature of Alamofires. I am trying to return a JSON response as a dictionary, but Xcode gives me "Dictionary does not convert to" Void "

func homePageDetails(userName:String) -> (Dictionary<String,AnyObject>){
    let username = userName
    let hompePageDetails = Alamofire.request(.GET, "http://example.com/API/Bunch/GetHomePageDetails/\(username)/").responseJSON{(request, response, JSON, error) in
    print(JSON)
    var test = JSON as Dictionary<String,AnyObject>
    return test
    }
}

Any help would be greatly appreciated.

+2
source share
1 answer

You are returning test: Dictionary<String,AnyObject>from a closure method, not from homePageDetails. The return return type Voidis why you get this error.

Alamofire, Alamofire.request . , . - . :

func homePageDetails(userName:String, completion:(Dictionary<String,AnyObject>) -> Void) {
    let username = userName
    let hompePageDetails = Alamofire.request(.GET, "http://example.com/API/Bunch/GetHomePageDetails/\(username)/").responseJSON{(request, response, JSON, error) in
        print(JSON)
        var test = JSON as Dictionary<String,AnyObject>
        completion(test)
    }
}
+9

All Articles