41772

Comparing iOS Parse SDK Class with another Class's objects

Question:

So what I'm trying to do essentially add a button next on each cell in my UITableView. Each cell in my tableView is being populated from my Event Class on parse where each object is displayed in a new cell.

Once a user hits this button it takes whatever Event object from the Event class they've clicked and possibly adds it to a "property" in the Parse User Class I'll create named "watching".

But how would I do something like this to where they're able to have all of these Events under the User Class "watching property"? Would I have to set up some relation of some sort?

Summary: Basically wanting to have a watch list people are able to watch any of the objects posted by any of the users in the Events Class. These objects that are being watched are added to a property in the User Class so that I can easily create a UITableView pulling the current users watching property list of items and displaying them.

Answer1:

I hope I have understood what you want ... If I understand it you need a form of relationship between the object and the CurrentUser viewing it ...

normally to identify the selected cell within a IBAction you can 'use this method:

- (IBAction) button: (id) sender { NSIndexPath * indexPath = [self.TableView indexPathForSelectedRow]; PFObject SelectedObject * = [self.YOUR_ARRAY objectAtIndex: indexPath.row]; }

This way you've identified which cell the current user has selected .. From this point on, continue with the PFObject to save the data the way you want

The essential thing is to set the goal of PFObject (in this case the selected cell) then continues to set the data to be set according to what you need

Answer2:

You could create a field on your PFUser class : @"watching"

Then use this as an array, so whenever the user clicks on something to watch ...

[[PFUser currentUser]addObject:objectToWatch.objectId forKey:@"watching"]; // adds it to the array [[PFUser currentUser]save]; // something about arrays and parse objects, if you're using operations like "addObject" you should save or you'll get errors. // the other option is to get an NSMutableArray from the array field, edit that, and reassociate it with the @"watching" key ... whichever you prefer

We now have an array of Id's associated with objects to watch. You could query like so

PFQuery * query = [PFQuery queryWithClassName:@"ObjectsToWatch"]; [query whereKey:@"objectId" containedIn:[PFUser currentUser][@"watching"]]; [query findObjectsInBackground]; // use a block method though

This is only one way to do it, hope it helps

Recommend

  • Do Vue watched properties cache just like the computed properties?
  • iOS app terminated due to memory pressure
  • can't get In-App-Purchase hosted content to be actually hosted
  • Using web client in Silverlight
  • Batching in py2neo
  • How do we set maximum_bad_records when loading a Bigquery table from dataflow?
  • ELMAH: Can you set it up to email errors only remotely?
  • R h2o.glm - issue with max_active_predictors
  • Checking if the Faye server exists before running it for my Rails app
  • Create function that can pass a parameter without making a new component
  • how to change api_token column in token guard
  • Can't remove headers after they are sent
  • Why cepheus don't send int without quotes to orion?
  • Adding elements to a huge XML file
  • Date Conversion from yyyy-mm-dd to dd-mm-yyyy
  • Debug.DrawLine not showing in the GameView
  • How can I sort a a table with VBA with given text condition?
  • Installing iPhone App to iPhone
  • Why Encoding.ASCII != ASCIIEncoding.Default in C#?
  • Abort upload large uploads after reading headers
  • How to define and use opencv mat of user type
  • Is it possible to access block's scope in method?
  • C++ Partial template specialization - design simplification
  • ImageMagick, replace semi-transparent white with opaque white
  • NHibernate Validation Localization with S#arp Architecture
  • CSS Linear-gradient formatting issue accross different browsers
  • Is calc() supported in html email?
  • How to make a tree having multiple type of nodes and each node can have multiple child nodes in java
  • Cassandra Data Model
  • Data Validation Drop Down Box Arrow Disappearing
  • Codeigniter doesn't let me update entry, because some fields must be unique
  • Getting Messege Twice Using IMvxMessenger
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • Turn off referential integrity in Derby? is it possible?
  • Add sale price programmatically to product variations
  • Does armcc optimizes non-volatile variables with -O0?
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • Unable to use reactive element in my shiny app
  • Python/Django TangoWithDjango Models and Databases
  • How do I use LINQ to get all the Items that have a particular SubItem?