为了排除项目问题,我创建了一个全新的单一视图项目并添加了以下podfile:
target 'App' do
use_frameworks!
pod 'Firebase'
pod 'Firebase/Auth'
pod 'Firebase/Database'
end
然后我添加了以下代码:
import UIKit
import FirebaseDatabase
class ViewController: UIViewController {
let ref = FIRDatabase.database().reference()
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
ref.observeEventType(.Value) { (snapshot) in
}
}
}
结果是以下错误:
不明确地使用'observeEventType(_:withBlock :)'
使用:
找到此候选人(FirebaseDatabase.FIRDatabaseReference)
找到此候选人(FirebaseDatabase.FIRDatabaseReference)
我正在使用Xcode 7.3.1,podfile.lock如下:
PODS:
- Firebase (3.3.0):
- Firebase/Core (= 3.3.0)
- Firebase/Analytics (3.3.0):
- FirebaseAnalytics (= 3.2.1)
- Firebase/Core (3.3.0):
- Firebase/Analytics (= 3.3.0)
- Firebase/Database (3.3.0):
- Firebase/Analytics (= 3.3.0)
- FirebaseDatabase (= 3.0.2)
- FirebaseAnalytics (3.2.1):
- FirebaseInstanceID (~> 1.0)
- GoogleInterchangeUtilities (~> 1.2)
- GoogleSymbolUtilities (~> 1.1)
- GoogleUtilities (~> 1.3)
- FirebaseDatabase (3.0.2):
- FirebaseAnalytics (~> 3.2)
- FirebaseInstanceID (1.0.7)
- GoogleInterchangeUtilities (1.2.1):
- GoogleSymbolUtilities (~> 1.0)
- GoogleSymbolUtilities (1.1.1)
- GoogleUtilities (1.3.1):
- GoogleSymbolUtilities (~> 1.0)
DEPENDENCIES:
- Firebase
- Firebase/Database
SPEC CHECKSUMS:
Firebase: 6250071f0e2440a5c4c67b8cb6b868f868237ac3
FirebaseAnalytics: 0fd6532cb2c3d03cd5cf26ad295ccb091efd3104
FirebaseDatabase: 59bea2e7dfd81b3b8b2f8e396caf1a52c2ced6f7
FirebaseInstanceID: a9d923f3d0b6fbf9fac89310860357aaadc34be5
GoogleInterchangeUtilities: def8415a862effc67d549d5b5b0b9c7a2f97d4de
GoogleSymbolUtilities: 33117db1b5f290c6fbf259585e4885b4c84b98d7
GoogleUtilities: 56c5ac05b7aa5dc417a1bb85221a9516e04d7032
PODFILE CHECKSUM: 261a8ee435b8325808d7a0962ace0c908fd37368
COCOAPODS: 1.0.1
与observeSingleEventOfType(_:withBlock:)
答案 0 :(得分:7)
好像它是Swift bug,尝试使用这种语法(没有尾随闭包语法。):
ref.observeEventType(.Value, withBlock: { firDataSnapshot in
})
更多信息:Ambiguous use of 'observeSingleEventOfType(_:withBlock:)' error in Swift