could not find member convert from string interpolation segment - ios

I have a users class in my firebase JSON file .. it has the following child nodes:
Age
Location
About
Image
From my app I am trying to enter the age of the logged in user and update it in the JSON file.
I wrote the code :
ref.childByAppendingPath("users\(ref.authData.uid)/Age")
.updateChildValues(AgeTextField.text)
But it gives error:
could not find member convert from string interpolation segment
Please help me what line of code should I write to update the age and other info of logged in user?

The interpolation looks correct. However, you're most likely not authenticated. The authData property only exists when a user have been authenticated to the Firebase database.
There is another problem in the updateChildValues function.
updateChildValues expects a dictionary of [String: AnyObject]. This is a non destructive update. It will only update values provided in the dictionary.
Try this instead.
ref.childByAppendingPath("users\(ref.authData.uid)")
.updateChildValues(["age": AgeTextField.text])
But if you really want to drill down into the Age node you can just use setValue for a String update.
ref.childByAppendingPath("users\(ref.authData.uid)/Age")
.setValue(AgeTextField.text)
setValue is a destructive update. This means it will replace everything at that node's location. However, since you're only accessing a single property of a node it doesn't matter that the update is destructive.

Related

How to access object field in qaf step from stored variable

In my previous question I was looking for a way to access and store return value of the function in qaf step. I was provided with the following:
When create new user using "{'name':'user1','password':'user123'}"
And store into 'newUser'
Then system should have user '${newUser}'
Now, I'd like to know how to get value from object/collection stored.
If it is a simple object named newUser which has field Id. How would I pass Id on next step?
And, if return is List, how to get by index from stored list?
Resolved issue on my own. If anyone faces same unknowns, here is how I solved it.
For requirements to work around response data, parsing same stored objects in properties by specific fields or collecting data from other structures such as Maps or Lists, create common functions with #QAFTestStep annotation to get data for class member name, map by key or list by index and so on... Add those in common steps and then write stepname text in gherkin format with parameters specified. Let me know if someone needs help, always ready to help out...

Firebase: What's the correct way to update values?

If my database structure is like this:
and I have this:
ref = Database.database().reference().child(passUserID)
ref?.child("wins").updateChildValues("wins": numerator)
where numerator = (games played beforehand) + (games played after logging in), for the second statement it is giving me an error in the expression that I don't know how to fix.
Also if I try to do this instead:
ref?.child("wins").setValue(numerator)
it messes up my data bad and gives a bad instruction error.
The updateChildValues method takes a Dictionary. So you just need to call the method with a dictionary containing the key-value pairs you want to update, i.e.
ref = Database.database().reference().child(passUserID)
ref?.updateChildValues(["wins": numerator])
For more on how to read/write data to firebase realtime database, refer to: https://firebase.google.com/docs/database/ios/read-and-write
If you use .setValue triggers only in the beginning. Instead of .setValue use updateChildValues(.values/.childAdded/.childRemoved etc..) to update the values inside your tree. It will be executed whenever changes occurs to your node.
How to update particular value of child in Firebase DB

How to update value in angular ui typeahead directive if no matching option is found

I've an array of objects containing title and salary which is used in typeahead directive.
I display department name and get entire object as value.
If none of the options match, I want user entered string to be converted to object still. Is there any way to update that?
This answer is pretty late, but I would just use ng-blur (to trap the end of the users input) along with a variable bound to typeahead-no-results. Then test if the variable is true in the method bound to ng-blur, and, if so, make an object out of the String supplied by the user and push it to your data source. Simple example found here.

Parse SaveEventually Issue in iOS Swift

I'm facing an issue with save eventually.
I'm retrieving an object from Parse the object contains a pointer for a User.
I'm trying to update the object and save it with a different user.
object.incrementKey("Likes")
object.addObject((PFUser.currentUser()?.objectId)!, forKey: "LikesUsers")
object.saveEventually()
it works once or twice and then it generates this Error and the app crashes :
Caught "NSInternalInconsistencyException" with reason "User cannot be
saved unless they have been authenticated via logIn or signUp
I think the user pointer shouldn't be saved ! and I would like to know if there is any function to tell Parse to not save the User and modify the dirty value.
You should explain what kind of object we're looking at. Is this a "likes" object, or is the "photo" object?
I'm guessing object is a photo or sth that other users kan like. And that what you're trying to do is to save a "like" for the current photo.
Your screenshot is not showing us the LikesUsers column, which is the one you are trying to save to. I will therefore guess that LikesUsers is an array of pointers.
Your code should then be like this:
object.incrementKey("Likes")
object.addObject(PFUser.currentUser()!, forKey: "LikesUsers")
object.saveEventually()
For this to work, the current user must of course be authenticated already.
Be aware that if you have a lot of users, you may face problems if there are thousands of likes on a photo when you store them all in an array of pointers.

Firebase: Swift - Query value in child node without knowing the parent key

I have a firebase database which I have imported a list of approx. 8200 Universities with the details seen above.
I want to be able to enter an email address into a text field then query the "domain" part of this JSON. My issue is I need to query all the domains in the list of 8000, however I do not know how to search domain ad I do not have the "7542" to use a childByAppendingPath.
So I have a reference to "universities" but I need to be able to query "domain" without knowing the parent key (i.e. 7542 in the example above, but I want to search the domain, "iautb.ac.ir").
You need to create a reference and Query that reference, check this link to find more about how to retrieve data from firebase.
Basically you need to do something like this
let myRef = Firebase(url: "https://your.firebaseio.com/universities")
let query = myRef.queryOrderedByChild("domain").queryEqualToValue("yourDomainSearchValue")
and then observe the events you need to on your query

Resources