swift2 在Swift 2中,无法将类型()的值转换为闭包结果类型NSDictionary

pkwftd7m  于 2022-11-06  发布在  Swift
关注(0)|答案(3)|浏览(217)

我必须返回此函数的值。我在此行中遇到错误

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

jxct1oxe1#

"这肯定行"

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

"然后用它来“

var dict = NSDictionary()
temp.GetStation("your url") { (stationDictionary) -> NSDictionary in
    dict = stationDictionary;
    print("your dictionary := \(stationDictionary)")
}
yeotifhr

yeotifhr2#

实际上,您可能会错误的代码getResonse...它应该像下面这样...

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

因此,您应该像下面这样调用GetStation ...

func GetStation(url : String, completionHandler: (stationDictionary: NSDictionary) -> NSDictionary) {
    getResonse(url) { (dictionary) -> Void in
        return completionHandler(stationDictionary: dictionary)
    }
}
wb1gzix0

wb1gzix03#

func GetStation(url : String, completionHandler: (stationDictionary: NSDictionary) -> ()) {
    getResonse(url) { (dict) -> NSDictionary in
        completionHandler(stationDictionary: dict)
        return dict
    }
}

相关问题