Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Advice on setting up a Favorite List

lukeirvinlukeirvin Posts: 388Registered Users @ @
I am using Parse.com as my backend.

I would like to keep the Favorite list unique to each user without having them create an account.

Let's say I have a table of items, each with it's own unique detail page.

Example:

Item A
Item B
Item C
Item D

Within the detail page will be info, and a "Star" to "Favorite" that page.

I have another table that will display the "Favorite" Items.

I'm using [NSUserDefaults] but also triggering a BOOL value in Parse.

The issue this causes is the way I am querying the table, if User A favorites Item A, then every user will see this.

What would be the best method to keep each experience unique to each user?

Should I continue using [NSUserDefaults] but send the object to that?

Replies

  • BrianSlickBrianSlick Treadmill Desk Ninja Posts: 10,689Tutorial Authors, Registered Users @ @ @ @ @ @ @ @
    Not entirely sure I follow, but in summary:

    You have some objects. These objects are shared amongst all users. Because they are shared, it would not be appropriate to have BOOL isFavorite on them, because it needs to be a per-user value, not a per-object value.

    If this is correct, then basically you need to keep track of the favorite objects separately, or keep track of something about the favorite objects that will let you match things back up later. For example, Item A could have an identifier @1234ABCD that is never visible to the users. In this case, you could keep a list of these identifiers. You might have a handful of helper methods for this:
    + (void)addItemToFavorites:(MyObject *)object;
    + (void)removeItemFromFavorites:(MyObject *)object;
    + (BOOL)isItemAFavorite:(MyObject *)object;
    

    Or maybe
    + (void)toggleFavoriteStatusForItem:(MyObject *)object;
    + (BOOL)isItemAFavorite:(MyObject *)object;
    

    What you do inside these is up to you. Read the identifier property, add it to an array, put the array in user defaults. Get the list of favorite identifiers from user defaults, find out if the current identifier is there, then you know whether or not it is a favorite.
    Professional iOS App Development. Available for hire.
    BriTer Ideas LLC - WWW | Facebook | Twitter | LinkedIn

    BTIKit | BTICoreDataKit | SlickShopper 2 | Leave a PayPal donation
  • DomeleDomele Posts: 2,991Registered Users @ @ @ @ @
    Instead of setting a flag on the actual object in Parse, create a relationship between your Parse object and PFUser. Whenever your user favorites something, add the object to the relationship.

    Here's some sample code from the Parse help site I found:
    PFObject *post = ...;
    
    PFUser *user = [PFUser currentUser];
    PFRelation *relation = [user relationforKey:@"posts"];
    [relation addObject:post];
    [user saveInBackground];
    

    When you want to query, use the query object provided by PFRelation.
    If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.<br />
    <br />
    New app - See screenshots and details at <a href="http://www.globaclock.com"; target="_blank">www.globaclock.com</a>.<br />
    <br />
    If you want to
  • lukeirvinlukeirvin Posts: 388Registered Users @ @
    edited December 2013
    I'd like to keep away from having users create an account for this app.

    I did think along the PFRelation side of things, but that will be a last call.

    EDIT:

    I learned about anonymous users, so this approach should work.

    I'm able to see the info in my object, but when I view my Relations on Parse, nothing appears. Working on that part now.
    Post edited by lukeirvin on
  • lukeirvinlukeirvin Posts: 388Registered Users @ @
    I have tried what Domele has suggested, but when I "View Relations" I just get back the Users as the relations, and not the object.
  • DomeleDomele Posts: 2,991Registered Users @ @ @ @ @
    edited December 2013
    Wait. I thought you wanted to sync these favorites to the cloud as you were setting the favorite flag on the actual Parse object. If you just want to keep these favorites local, then you can just simply use the system Brian described.

    In this case, flag the objectIds of the Parse object. Every single one has a unique one so you shouldn't run into any problems. When you want to query for these favorites, use whereKey:containedIn:. key will be objectId and containedIn will be an array of object ids that your user has favorited.
    If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.<br />
    <br />
    New app - See screenshots and details at <a href="http://www.globaclock.com"; target="_blank">www.globaclock.com</a>.<br />
    <br />
    If you want to
Sign In or Register to comment.