Leem.fin Leem.fin - 21 days ago 7
iOS Question

Failed to initialize Firebase

I am developing an iOS project (with xcode 8 & swift 3). I have installed firebase pod through cocoapod. This is my pod:

target 'myApp' do
pod 'Firebase', '~> 3.9'
end


Then I open myApp.xcworkspace file, the project is opened in Xcode.

Then I try to initialize a firebase instance by:

let BASE_URL = "https://myapp-35211.firebaseio.com/"
// ERROR: Cannot call value of non-function type 'module<Firebase>'
let firebase = Firebase(url: "\(BASE_URL)")


(I have
import Firebase
)

I am trying to use firebase database.

Why I get the above error?

====== UPDATE =======

OK, I followed the steps to initialize Firebase (add my project in Firebase, download the GoogleService-Info.plist & use
FIRApp.configure()
, etc). Now I get this error:

enter image description here

Why?

My Podfile is like this:

target 'myApp' do
pod 'Firebase', '~> 3.9'
end


Does it mean this pod doesn't include
Firebase/Database
???

===== UPDATE AGAIN =====

OK, add
'Firebase/Database'
to Podfile solved the above issue, but why
'Firebase'
pod doesn't include
Firebase/Database
? Isn't it a subset of
'Firebase'
pod?

Answer

I'm not sure why are you using the base url on your code, because now, when you are setting up your firebase project, you can link your app project with your firebase project passing your Bundle identifier.

Take a look on the firebase documentation: https://firebase.google.com/docs/database/ios/start

If you do so, then you just need to do 2 steps:

1 - On you appDelegate over didFinishLaunchingWithOptions: add:

FIRApp.configure()

2 - On the class that you want to take your firebase reference you can do:

let ref = FIRDatabase.database().reference()

This way you will have on ref the reference to the root of your firebase database

Comments