Cannot Call Value of Non-Function Type 'Module<Firebase>'

How to fix Cannot call value of non-function type [UserInfo] while trying to retrieve provider's data?

providerData is an array property of FIRUser check Here, that you can't use { after it , so you need

for profile in user.providerData {
if profile.providerID == "facebook.com" {
let fbUserId = profile.uid
fbProfilePicUrl = "https://graph.facebook.com/\(fbUserId)/picture?height=300"
self.profilePicUrl = fbProfilePicUrl
}else if profile.providerID == "google.com" {
let googleUserId = profile.uid
//self.profilePicUrl = .....
}
}

Cannot call value of non-function type 'Any?!' :- Firebase,Swift3

See the issue is that when you are instancing and initialising your variable you are telling it that the value its gonna receive will be a value for the object named Dogs present in this snapshot whose type is AnyObject.

But snapshot.value is of type Dictionary i.e [String:AnyObject],NSDictionary..

And the Dogs node that you retrieve is of type, either Dictionary or an Array.

Basically you should avoid to store a value in a variable, of type AnyObject

Try this:-

      FIRDatabase.database().reference().child("Posts").child("post1").observe(.childAdded, with: { snapshot in
if let currentData = (snapshot.value! as! NSDictionary).object(forKey: "Dogs") as? [String:AnyObject]{

let mylat = (currentData["latitude"])! as! [String]
let mylat2 = Double((mylat[0]))
let mylon = (currentData["longitude"])! as! [String]
let mylon2 = Double((mylon[0]))
let userid = (currentData["User"])! as! [String]
let userid2 = userid[0]
let otherloc = CLLocation(latitude: mylat2!, longitude: mylon2!)
self.distanceBetweenTwoLocations(self.currentLocation, destination: otherloc, userid: userid2)
}
})

PS:- Seeing your JSON structure you might wanna convert it into a Dictionary not a Array

Cannot call value of non-function type

Try changing the method as:

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: NSIndexPath) -> UICollectionViewCell{
let cell = super.collectionView(collectionView, cellForItemAt: indexPath) as! JSQMessagesCollectionViewCell

let message = messages[indexPath.item]

if message.senderId == senderId {
cell.textView!.textColor = UIColor.whiteColor()
} else {
cell.textView!.textColor = UIColor.blackColor()
}

return cell
}

If you are writing an overridden method correctly, Swift complains about missing override keyword. So, if you cannot find any warnings or errors on this overridden method, you are very likely misusing method signature.

And many UICollectionViewDataSources methods are renamed, in Swift3 "cellForItemAtIndexPath" has this signature:

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell

So, Swift cannot find a method definition matching collectionView(_:cellForItemAtIndexPath:), so assuming the collectionView there would be a property. (Unfortunately, it is declared in JSQMessagesViewController.)

You may have this sort of mismatching method implementations in your class. Better check them all.

Cannot call value of non-function type 'String'

The error is telling you that you are trying to call a String instead of a method (struct constructor in your case). You've probably declared a String variable named ILT (uppercase) somewhere else and that's why it fails.

Your posted code works fine so the error must be somewhere else in your code.

Ambiguous use of 'subscript' and Cannot call value of non-function type 'AnyObject' errors retrieving data from Firebase in SWIFT 4.1

You changed [] to ()

let dic = snapshot.value as! [String:String]
let date = dic["Date"]
let time = dic["Time"]
let latitude = dic["Latitude"]
let longitude = dic["Longitude"]
let desc = dic["Description"]

Cannot call value of non-function type UIAlertAction

Fixed it. Changed:

errorController.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))

to:

errorController.addAction(UIKit.UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))


Related Topics



Leave a reply



Submit