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

无法在Swift 2中将类型()的值转换为闭包结果类型NSDictionary,swift,swift2,Swift,Swift2,我必须返回此函数的值。我在这行中遇到错误 func GetStation(url : String, completionHandler: (stationDictionary: NSDictionary) -> ()) { getResonse(url, completionhandler: { (dict) -> NSDictionary in completionHandler(stationDictionary: dict) // Error on th

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

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

这肯定会奏效。

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)")
}

实际上,您可能会为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)
    }
}

您能打印您收到的响应吗?我的代码没有执行,它们显示errorcompletionHandler(stationDictionary:dict)为?NSDictionary当我使用此行代码执行get response但在此行崩溃时尝试使用
completionHandler(stationDictionary:dict as?NSDictionary)
您能显示URL吗?你也在使用框架吗?对不起,我对你的答案投了高票,毁了你“666”的声誉嗨…这个答案有效吗?应该有效。因为我已经在xcode中测试过了。
func GetStation(url : String, completionHandler: (stationDictionary: NSDictionary) -> NSDictionary) {
    getResonse(url) { (dictionary) -> Void in
        return completionHandler(stationDictionary: dictionary)
    }
}