我正在尝试在 Swift 中实现新的 REST 服务,但我迷失了。我需要删除服务收据中的“可选”字符串:
func callServiceReceives(){
var jsonReceived: JSON = []
Alamofire.request(.GET, "http://localhost:8080/userServicesProvider")
.responseJSON { (_, _, pruebaJSON, _) in
jsonReceived = JSON(pruebaJSON!)
println(jsonReceived["recibos"].array?.count) // "Optional(4)"
}
}
// If i try if let temp:String! = String(stringInterpolationSegment: jsonReceived["recibos"].array?.count) {
// println(temp) -> "Optional(4)"
// } -> say me "Bound value in a conditional binding must be of Optional type"
//If i try -> let temp:String! = String(stringInterpolationSegment: jsonReceived["recibos"].array?.count)
//
// if let temp2 = temp!{
// println(temp2) -> "Optional(4)"
//} -> i had the same problem: "Bound value in a conditional binding must be of Optional type"
你能帮帮我吗?
非常感谢
最佳答案
您将 !
放在了错误的位置。它应该在这里:
println(jsonReceived["recibos"].array?.count!)
不过,为了安全起见,您最好:
println(jsonReceived["recibos"].array?.count.map{String($0)} ?? "Error")
如果你的数组为 nil,这将打印“错误”,或者:
jsonReceived["recibos"].array?.count.map(println)
如果您的数组为零,则不会打印任何内容。
关于ios - 删除可选的 Alamofire(以及任何地方),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31137648/