我正在使用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
你有沒有設法獲得此修復? –