Adam Zarn Adam Zarn - 3 months ago 31
iOS Question

Using Firebase push() to create a list

Here is the reference I created to my Firebase database

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


However, when I try to use this as the base_url for a push(), I get this error:

Value of type 'FIRDatabaseReference' has no member 'push'


I tried to change my base_url to this:

let ref = Firebase.database().ref()


But then I get

Module 'Firebase' has no member 'database'


Here's my Podfile. Am I missing something? I have imported Firebase at the top of my file.

# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'

target 'ValleybrookMessenger' do
# Comment this line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!

# Pods for ValleybrookMessenger

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

target 'ValleybrookMessengerTests' do
inherit! :search_paths
# Pods for testing
end

target 'ValleybrookMessengerUITests' do
inherit! :search_paths
# Pods for testing
end

end

mjr mjr
Answer

Swift doesn't have a push() method, so the equivalent you probably want is childByAutoId().

The first way you created the reference is correct:

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