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];
Related
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.
I want to create an anonymous user on Parse.
I would like that anonymous user to have a field for 'language' which will save the device's default language.
My PFUser object has a field 'language'.
Is there a way to save [PFUser current][#"language"] BEFORE calling logInWithBlock??
Or do I have to wait for the completion block and then save a second time...
Someone swiftly answered on the official Parse GitHub Page:
PFAnonymousUtils w/ fields
I have a logic problem in my app using Parse, Regarding which path to choose to save in traffic, and if someone has already faced a similar problem, I will really appreciate the help. Also, you can end up helping other developers facing the same problem
I have a social app where there is a feed with objects, and users can bookmark ("favorite") these objects
I studied the Parse documents and concluded that among the pointers, relations and arrays, the best way to store favorite would be a objectId's array stored in the class of users. Each time an object is bookmarked by the user, the ObjectID of this object is stored in a objectID's array belonging to that user. The reason for the choice is:
It is easy to create the bookmark's view and show them to the user, since I just have to search for the user's ObjectID's array and finding those present in the class of objects
Saving only the objectID and not the entire object, I will save in traffic and I keep the app and traffic clean
But my logic problem is as follows. If user1 has created an object, and user2 bookmarked it, and then user1 decided to delete the object, I would have to search the objectID of this deleted object in each favorite array of each user!
So my question is, what would be less expensive for traffic of my App? Store the entire object when a user bookmark it, automating removal when a user deletes the object? Or just store the ObjectID, and perform the search on each array for each user when this object is deleted?
You can create Parse class for your feed objects. After that create an array column to store objectIds of users who added your feed item to favorit. When you want to find all the objects specific user bookmarked do something like
PFQuery *query = [PFQuery queryWithClassName:#"feedObjects"];
[query whereKey:#"favoritesArray" equalTo:#"YOUR USER OBJECT ID"];
[query findObjectsInBackground];
To remove object simply do
PFObject *feedItem = [PFQuery getObjectOfClass:#"feedObjects" objectId:#"ITEM TO REMOVE OBJECTID"];
[feedItem deleteInBackground];
Hope that helps :)
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
I have dug through a few of the tutorials at parse.com and I don't have a problem with users creating objects and storing them in Parse.
What I don't know how to do is passing an object to another user. So, for example, if I have users with their own to do lists, and a friend wants to add to another users' to do list, how would I go about doing that? So one user would create the object:
PFObject *task = [PFObject objectWithClassName:#"ToDo"];
[task setObject:#"Do the dishes" forKey:#"userName"];
[task save];
But I'd like this user to pass the task to a friend of theirs, so when their friend launches the app, they see the task added to their list.
I'm using the Facebook SDK as well, so if there's something there that could help, I could use that.
I haven't used Core Data before, so I was hoping to handle a lot of the backend work with parse so I could avoid the learning curve for the time being.
Thanks for all the help
I'd like to add that I'm not necessarily looking for an "answer". I just haven't done anything like this before so, I wouldn't know where to look.
You want to use user pointers & ACLs for this.
// assume PFUser *assigned
PFACL *acl = [PFACL ACLWithUser:PFUser.currentUser];
[acl setReadAccess:YES forUser:assigned];
PFObject *todo = [PFObject objectWithClassName:#"Todo"];
todo[#"task"] = #"Wash dishes";
todo[#"user"] = assigned;
todo.ACL = acl;
[todo saveInBackground];
Now, you can see all TODOs with
[PFQuery queryWithClassName:#"Todo"];
You can see all queries which are assigned to you with
[query whereKey:#"user" equalTo:PFUser.currentUser];
And only the creator of a TODO can edit it.
It seems that you have a many to many relationship here : a user can own many todo objects and a todo object can be own by many users.
This kind of approach can be handle with PFRelation object. Take a look at the official blog post here : http://blog.parse.com/2012/05/17/new-many-to-many/
I wouldn't handle it as a many to many relationship in this case.
The person who creates the todo object should be the only owner. You can add an attribute to the todo object and it's type can be an array. The array can then keep track of who it's shared with. If someone it's shared with deleted it you can then just remove them from the array or if the owner deletes it the object can just be deleted.