我必须返回此函数的值。我在此行中收到错误
func GetStation(url : String, completionHandler: (stationDictionary: NSDictionary) -> ()) {
getResonse(url, completionhandler: { (dict) -> NSDictionary in
completionHandler(stationDictionary: dict) // Error on this line
})
}
答案 0 :(得分:3)
这肯定有效。
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)")
}
答案 1 :(得分:0)
let myStr = "POINT(101.650577657408 3.1653186153213)"
let strWithout_POINT_openingBrace = myStr.stringByReplacingOccurrencesOfString("POINT(", withString: "")//"101.650577657408 3.1653186153213)"
let strWithout_closingBrace = strWithout_POINT_openingBrace.stringByReplacingOccurrencesOfString(")", withString: "")//"101.650577657408 3.1653186153213"
//now you have only space between two values
//so split string by space
let arrStringValues = strWithout_closingBrace.componentsSeparatedByString(" ");//["101.650577657408","3.1653186153213"]
print(arrStringValues[0]);//first value "101.650577657408"
print(arrStringValues[1]);//second value "3.1653186153213"
答案 2 :(得分:0)
你可能错误的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)
}
}