【发布时间】:2016-09-17 20:22:59
【问题描述】:
这是我在迁移到 Swift 3 之前的代码:
ref.observeEventType(.ChildAdded, withBlock: { snapshot in
let currentData = snapshot.value!.objectForKey("Dogs")
if currentData != nil {
let mylat = (currentData!["latitude"])! as! [String]
let mylat2 = Double((mylat[0]))
let mylon = (currentData!["longitude"])! as! [String]
let mylon2 = Double((mylon[0]))
let userid = (currentData!["User"])! as! [String]
let userid2 = userid[0]
let otherloc = CLLocation(latitude: mylat2!, longitude: mylon2!)
self.distanceBetweenTwoLocations(self.currentLocation, destination: otherloc, userid: userid2)
}
})
这是我迁移到 Swift 3 之后的代码:
ref.observe(.childAdded, with: { snapshot in
let currentData = (snapshot.value! as AnyObject).object("Dogs")
if currentData != nil {
let mylat = (currentData!["latitude"])! as! [String]
let mylat2 = Double((mylat[0]))
let mylon = (currentData!["longitude"])! as! [String]
let mylon2 = Double((mylon[0]))
let userid = (currentData!["User"])! as! [String]
let userid2 = userid[0]
let otherloc = CLLocation(latitude: mylat2!, longitude: mylon2!)
self.distanceBetweenTwoLocations(self.currentLocation, destination: otherloc, userid: userid2)
}
})
然后我在第二行得到一个错误:
不能调用非函数类型'Any?!'的值
我唯一尝试的是将第二行更改为以下代码:
snapshot.value as! [String:AnyObject]
但这是不对的,其中没有包含“Dogs”,它警告我distanceBetweenTwoLocations 代码从未使用过。
【问题讨论】:
标签: ios swift firebase firebase-realtime-database