我正在使用Firebase的应用程序。从Swift 3.0的Firebase中获取数据
今天3.0移动迅速后,Xcode的问我这个代码更改:
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)
}
})
这个代码:
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)
}
})
但在第二行它给了我一个错误:
Cannot call value of non-function type 'Any?!'
这是FireBase中的json数据:
{
“user1” : {
"Dogs" : {
"User" : [ "siACmQZ7MDclDSO3hrCOp953kfl2" ],
"latitude" : [ "32.172344" ],
"longitude" : [ "34.858068" ]
}
“user2” : {
"Dogs" : {
"User" : [ "siACmQZ7MDclDSO3hrCOp953kfl2" ],
"latitude" : [ "32.172344" ],
"longitude" : [ "34.858068" ]
}
“user3” : {
"Dogs" : {
"User" : [ "siACmQZ7MDclDSO3hrCOp953kfl2" ],
"latitude" : [ "32.172344" ],
"longitude" : [ "34.858068" ]
}
}
你能提供你的最小JSON,文本不片断 – Dravidian
@Dravidian当然,做 – Eliko
你有没有设法获得此修复? –