I am following Google's instructions on setting up Firebase https://www.firebase.com/docs/ios/quickstart.html
I suspect the problem may be because the help is for the legacy version. However deprecated should not read an error, at least I have found this for apple deprecations. The following code:
import UIKit
import Firebase
class FirstViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var myRootRef = Firebase(url:"https://<YOUR-FIREBASE-APP>.firebaseio.com")
// Write data to Firebase
myRootRef.setValue("Do you have data? You'll love Firebase.")
// Do any additional setup after loading the view, typically from a nib.
}
gives the following error
Cannot call value of non-function type 'module<Firebase>'
From the link, this is the exact same code prescribed. I have installed pods for Firebase and Firebase Cloud Messaging.
Cannot call value of non-function type 'module'
The error is saying that you imported a module named Firebase here:
import UIKit
import Firebase
And then you tried calling the module as if it's a function:
override func viewDidLoad() {
super.viewDidLoad()
var myRootRef = Firebase(...)
I think the old Firebase module must have defined a function/class called Firebase, so that when you imported the old Firebase module, that made the Firebase() function/initializer available. Apparently, the new Firebase module doesn't define that function/class anymore, hence the need for the new instructions.
In addition, your url can't be correct:
url:"https://<YOUR-FIREBASE-APP>.firebaseio.com"
You would substitute the actual name of your app in place of <YOUR-FIREBASE-APP>.
In any case, you don't specify a url in your code anymore: instead you call FIRApp.configure() in AppDelegate.swift, and that takes care of connecting to the proper url for you. How does configure() know which url to connect to? Look in the GoogleService-Info.plist file that you dragged into your app--you’ll see the db url in there.
To get a reference to the top of your db, all you do is:
dbRef = FIRDatabase.database().reference()
Here it is in a ViewController:
class ViewController: UIViewController {
var dbRef: FIRDatabaseReference!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
dbRef = FIRDatabase.database().reference()
dbRef.child("person").child("name").setValue("Joe")
After running your app, you'll see something like the following at the Firebase website:
abcd-1234
|____person
|__name: “Joe”
I found a tutorial that works. Its by google so its up to date with the new Firebase.
https://codelabs.developers.google.com/codelabs/firebase-ios-swift/#0
Related
I am trying to create my first framework ,
What I am trying to do is, I have added one public method to read the config json (dictionary) from app level. So I need app to pass this config dictionary and read using framework.
I have add framework all correctly and then imported it in app and tried to create instance but getting following error
“ 'Platform' initializer is inaccessible due to 'internal' protection leve
“
Here. “Platform is framework name.
Here is the code in framwork side
import Foundation
public class Platform {
public init(){
}
public func readConfigFileFromApp(config:Dictionary<String, String>) {
print (config)
//Read the configfile from app and save it here for rest of the SDK use
}
}
On app side i tried this line
import UIKit
import Platform
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let platform = Platform() . **//Getting error 'Platform' initializer is inaccessible due to 'internal' protection level**
// Do any additional setup after loading the view.
}
}
please help
I have an app that was originally developed in Swift 2 / Xcode 7.3.1 using the Firebase iOS SDK v2.5.1 which is currently being updated to the latest versions of Swift/Xcode, which entails also updating the Firebase SDK.
We have hundreds of unit tests that were developed that, for the most part have been easy to update, but there are a few in particular that are tricky due to the way the old Firebase SDK was structured (and thus how it was used).
Originally, because nearly all Firebase database functionality was encompassed in one "Firebase" class, we created a custom class that inherited from the Firebase class that overrode several methods. In the latest SDK, functionality has been split further into different classes (namely the separate of Database and DatabaseReference), and most of the methods that were overridden are now a part of the DatabaseReference class in the FirebaseDatabase framework.
To make this a bit more tangible.
Old code:
class FirebaseTest: Firebase {
override func childByAutoId() {
//generate and save Auto ID internally to be used later for testing/validation
super.childByAutoID();
}
//many other overridden methods
}
//Unit tests
let fbref = FirebaseTest(url: "my-firebase.firebaseio.com/test");
// etc
The old Firebase SDK would return a Firebase reference to the base URL provided in the constructor, and because many of the properties we used were members of Firebase, all of our testing worked.
Following the SDK migration guide, I end up with the following code (simply replacing Firebase with DatabaseReference):
class FirebaseTest: DatabaseReference {
override func childByAutoId() {
//generate and save Auto ID internally to be used later for testing/validation
super.childByAutoID();
}
//many other overridden methods
}
//Unit tests
let fbref = FirebaseTest(fromUrl: "my-firebase.firebaseio.com/test")
// etc
Now, immediately, there is a problem with the above code that prevents it from compiling: the DatabaseReference constructor does not take any arguments. I can change it to the following
let fbref = FirebaseTest();
but now I know that, while it will compile, the tests will absolutely fail. The tricky part is that, in the latest SDK, database references are only supposed to be retrieved from a Database as follows:
//don't do this!
let fbref = DatabaseReference(); //will compile, but will break at runtime. Upon inspection in the debugger, there are several internal properties that should be set that are null. Those internal properties are likely all set correctly if the database reference is obtained correctly
//do it one of these ways
let fbref2 = Database.database().reference();
let fbref3 = Database.database().reference(fromUrl: "my-firebase.firebaseio.com/test") //also have access to this "reference(fromUrl: )" method from Database.database()
let fbref4 = Database.database().reference(withPath: "/test") //also have access to this "reference(withPath: )" method from Database.database()
So, hopefully my conundrum is becoming clear -- because I can only retrieve a correctly-initalized DatabaseReference from a Database, rather than my version of DatabaseReference that has overridden methods for testing, I'm fairly stuck.
Also, I have looked into creating an extension of Database itself as follows:
class FirebaseTest: DatabaseReference {
override func childByAutoId() {
//generate and save Auto ID internally to be used later for testing/validation
super.childByAutoID();
}
//many other overridden methods
}
class FirebaseDatabaseTest: Database {
override func reference(fromUrl: String) {
return FirebaseTest();
}
}
let fbref = FirebaseDatabaseTest().reference(fromUrl: "my-firebase.firebaseio.com/test")
But, even though I am intercepting the url in the overridden reference method, there's no clear way for me to "set up" the DatabaseReference the correct way using that URL.
Thoughts?
I have installed TwitterKit via CocoaPods due to it not being available in the Fabric OSX app. I'm trying to get a timeline view integrated into the app. It acts like it's loading but never shows any output in the console and never actually loads anything.
import UIKit
import TwitterKit
import Fabric
class updatesTVC: TWTRTimelineViewController{
convenience init() {
let client = TWTRAPIClient()
let dataSource = TWTRUserTimelineDataSource(screenName: "resurrectionwv", apiClient: client)
self.init(dataSource: dataSource)
}
}
I'm following a tutorial online. This tutorial covers firebase 1, however I'm currently using firebase 2
In one of the code samples he has written a reference like so
private var postRef: firebase
however when I do this within firebase 2 I get the error "Use of undeclared type 'firebase'
Now my issues is I'm trying to find the comparison between firebase 1 and 2 so I can go ahead an implement the correct code, however I've been unsuccessful in finding such information.
Can someone shed some light in regards to what the correct syntax is for firebase 2 ?
The value he assigns to this variable is a value from one of the tables, in this case its from a post table, which consists of Desc, image, Id
just change :-
private var postRef: firebase
to
private var postRef: FIRDatabaseReference!
Which you can later initialise in any scope...like:-
override func viewDidLoad(){
super.viewDidLoad()
postRef = FIRDatabase.database().reference()
}
First off, I know similar questions have been asked before and I've tried following the advice of this stackoverflow answer here to no avail. I also tried adding the basic gist of this as a comment, but I don't have enough rep yet :( Basically I am trying to use PFSubclassing to extend Parse's PFUser model. As such, here's my corresponding code:
User.swift:
import Foundation
import CoreLocation
class User : PFUser, PFSubclassing {
override init() {
super.init()
}
convenience init(email: String!) {
self.init()
self.email = email
self.username = email
}
// don't need to call User.registerSubclass() in AppDelegate because this
// is handling that here
override class func load() {
self.registerSubclass()
}
// Commented out because this is extending PFUser
// override class func parseClassName() -> String! {
// return "PFUser"
// }
}
Result on Tests:
-[PFObject _loadSensitiveUserDataFromKeychainItemWithName:]: unrecognized selector sent to instance 0x7f98ebc1c250
I'm also doing the following in my Bridging-Header:
#import <Parse/Parse.h>
#import <Parse/PFObject+Subclass.h>
If I un-comment "parseClassname() in User.swift" I get:
failed: caught "NSInvalidArgumentException", "Cannot initialize a PFUser with a custom class name."
Which leads me to believe that setting up the interfaces is at least partially working.
Based on all of the advice I've seen, I can't seem to figure out what I'm doing wrong. There is also an open bug that produces the same error message, but it is caused by using Parse's local data store and I haven't configured any of that.
At this point I feel like I am missing something dead obvious, or I am being affected by the same bug as mentioned above. Any suggestions?
Okay, solved my own problem here through trial and error. Essentially it looks like a cached logged in PFUser was causing problems. When Parse would initially load it was loading the logged in state from the emulator which was conflicting with the newly registered User subclass.
To fix this you can either:
Restart the emulator.
Call PFUser.logOut() right after Parse.setApplicationId() in AppDelegate to flush the cached user.
Hopefully this helps someone else out in the future!
I solved this issue by changing the initial view controller. It didn't register the user because it didn't go through the view controller that previously stated/identified who the user was.
What I did specifically:
Set the initial view controller, for the controller that captures who the user is and then segue your way past to where you want to be.
Restart the simulator.