doovers doovers - 4 months ago 5
Swift Question

Firebase 3: Ambiguous use of 'observeEventType(_:withBlock:)'

To rule out a project issue, I created a brand new single view project and added the following podfile:

target 'App' do
use_frameworks!

pod 'Firebase'
pod 'Firebase/Auth'
pod 'Firebase/Database'
end


I then added the following code:

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

}
}
}


The result is the following error:


Ambiguous use of 'observeEventType(_:withBlock:)'


with:


Found this candidate (FirebaseDatabase.FIRDatabaseReference)

Found this candidate (FirebaseDatabase.FIRDatabaseReference)


I'm using Xcode 7.3.1 and the podfile.lock is as follows:

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


Same issue with
observeSingleEventOfType(_:withBlock:)

Answer

It seems like it's a Swift bug, try to use this syntax instead (without trailing closure syntax.):

ref.observeEventType(.Value, withBlock: { firDataSnapshot in

})

More info: Ambiguous use of 'observeSingleEventOfType(_:withBlock:)' error in Swift