3

I have to return a value of this function.I am getting error in this line

func GetStation(url : String, completionHandler: (stationDictionary: NSDictionary) -> ()) {
    getResonse(url, completionhandler: { (dict) -> NSDictionary in
       completionHandler(stationDictionary: dict) // Error on this line 
    })
}
Olcay Ertaş
  • 5,987
  • 8
  • 76
  • 112
Chaman sharma
  • 41
  • 1
  • 2
  • 8

3 Answers3

3

This will surely work.

func GetStation(url : String, completionHandler: (stationDictionary: NSDictionary) -> NSDictionary) {
    getResonse(url, completionhandler: { (dict) -> NSDictionary in
       completionHandler(stationDictionary: dict) // Error on this line 
    })
}

and use it like,

var dict = NSDictionary()
temp.GetStation("your url") { (stationDictionary) -> NSDictionary in
    dict = stationDictionary;
    print("your dictionary := \(stationDictionary)")
}
Olcay Ertaş
  • 5,987
  • 8
  • 76
  • 112
Hitendra Solanki
  • 4,871
  • 2
  • 22
  • 29
0
func GetStation(url : String, completionHandler: (stationDictionary: NSDictionary) -> ()) {
    getResonse(url) { (dict) -> NSDictionary in
        completionHandler(stationDictionary: dict)
        return dict
    }
}
Olcay Ertaş
  • 5,987
  • 8
  • 76
  • 112
Chaman sharma
  • 41
  • 1
  • 2
  • 8
0

Actully you might wrong code for getResonse... It should be like below..

func getResonse(url : String, completionHandler: (dictionary:NSDictionary) -> Void) {
}

So you should call GetStation like below...

func GetStation(url : String, completionHandler: (stationDictionary: NSDictionary) -> NSDictionary) {
    getResonse(url) { (dictionary) -> Void in
        return completionHandler(stationDictionary: dictionary)
    }
}
Olcay Ertaş
  • 5,987
  • 8
  • 76
  • 112
Bhoomi Jagani
  • 2,413
  • 18
  • 24