i registered a User with PFUser and now i want to add a PfObject for each User something different, so like User A has in the PFObject the number 5 and User B has in the Object the number 8. How can i do that ? I used the PFSignUpViewController sample from Parse
If you are using Objective-c, use this code to create a random number.
int r = arc4random_uniform(74);
Then save the r to the user, the same way you save username and password.
user[#"randomnumber"] = r;
All users have a objectId in parse, so i donĀ“t see the point in doing what you are doing. And most of the information you need can be found in the docs.
https://parse.com/docs/ios/guide#users
Related
Is it possible to edit a string in a class on the Parse dashboard? For example, I have the following code:
PFObject *announcement1 = [PFObject objectWithClassName:#"Announcement1"];
announcement1[#"Body"] = #"Changes to training progression";
[announcement1 saveInBackground];
Essentially what I am trying to do is treat Parse like a database. I create a PFObject, call the class "Announcement1" and display the string "Body" in a label.
I've already created the query to pull the "Body" string in the label:
PFQuery *announcement1Query = [PFQuery queryWithClassName:#"Announcement1"];
[announcement1Query getObjectInBackgroundWithId:#"GvuO1ZUYwR"];
NSString *announcement1BodyText = announcement1[#"Body"];
announcement1Label.text = announcement1BodyText;
Now my question is, would it be possible to then go into my Parse dashboard and edit the "Body" string so as to update the label live with new information each time? If not, what would be the best way to go about doing this?
Thanks, Mustafa
Yes. You can update data in parse using dashboard. Parse doesn't support realtime DB, so you need to query the object or refresh object again to see the real data.
I have created a PFObject called UserDataTable which stores information like username, password, Name, emailID, age, city, state, etc. of the user.
I am not sure how to authenticate the user to server using PFObject but can do so using PFUsers(). I know that PFUsers is a sub-class of PFObject so there must be a way to access those properties using my PFObject.
Can anyone help me out with the same. I am using SWIFT for coding.
let UserDataBase = PFObject(className: "UserDataBase")
UserDataBase["userId"] = "aamirdbx"
UserDataBase["userName"] = "Aamir Bilal"
UserDataBase["userPassword"] = "pass"
UserDataBase["userEmailId"] = "aamirdbx#gmail.com"
I would like to Sign In using information in this UserDataBase which is a PFObject.
I know how we can do the same using PFUser() but I want to avoid using a bunch of different Objects.
You should be using PFUser for this no matter what. PFUser already has all the built in authentication protocols, session tokens, security and ACL built in for you, which as someone who is just getting started is not something you want to try and manage yourself. You can add extra information to your Parse User class if you need to store additional information, or you can create another table, and have a pointer in your user class to the data in the other table, but for your sake and your user's sake, please don't try to handle this yourself.
After that chunk of code you should call userDataBase.saveInBackground() or saveInBackgroundWithBlock but then you would have to do a lot more coding every time they log in to authenticate and sync objects with the user etc. The included PFUser subclass does a lot of the heavy lifting for you, plus you can add properties to the user subclass so that would probably be a better option.
So I have an object class called "Nootropic" on Parse, and I'm trying to save a specific object from the "Nootropic" class to a user as "Favorite", the problem I've been running into is when a user clicks "favorite" the object will become a "favorite" for all users, not just that one user.
Would appreciate any help/recommendations
You have to setup a One-to-Many Relationships between your ParseUser and the Favorite. Check this tutorial: https://parse.com/tutorials/one-to-many-relationships--2
Also as #neil suggest you should post some code.
First you have to get that user object using PFQuery. and then save favorite object in particular that user record.
For e.g. Store the favorite object in current login user then use this code.
PFUser * user = [PFUser currentUser];
PFObject *objfavorite = [PFObject objectWithClassName:#"favorite"];
user[#"favorite"] = objfavorite;
[user saveInBackground];
One of my fields for PFUser's is "ratingObject", a pointer to another class which has one column: "favouriteNumber". This keeps track of how many users follow this particular user. FavouriteNumber is just a number. I wanted to add this column directly to the PFUser row, however the app was crashing when I tried to increment this value from another user's account. Specifically when calling from user A:
userB.incrementKey("favouriteNumberInPFUser", byValue: 1)
userB.saveInBackground()
So I ended up creating this other class and adding a pointer to PFUser. However I need to perform a PFQuery taking into account this value. If it was in PFUser, no problem. But since it is in this other class, I can't really access it. I tried this:
var query2 = PFUser.query()
query2?.includeKey("ratingObject")
query2!.addDescendingOrder("ratingObject.favouriteNumber")
but it gives this error: [Error]: -ratingObject.favouriteNumber is not a valid order key (Code: 105, Version: 1.7.4)
It should be a number on the user, and it can be if you update it from cloud code. This could either be an explicit function, or it could be a save hook if the current user is modified when they favourite another user.
I'm building an app where emails are supposed to be the main identifiers. I don't want my users to have a username at all. I'm using Parse for backend and want to use the PFUser class for user signups etc. It seems like PFUser requires a username. Is there anyway to use PFUser without using username?
You can set emailAsUsername to true in signUpView as following:
signUpViewController.signUpView.emailAsUsername = true
I am in the same situation as you, but what I do is just set the email address my user enters for the username field. Now they can just login with their email address :)