Question

i'm losing my head over this one just can't figure it out .

my app has a text field and a button which you can submit your phone number or just a number ( it doesn't matter ) .

the button method is this

PFObject *addValues= [PFObject objectWithClassName:@"phoneNumber"];
[addValues setObject:phoneNumbers forKey:@"numbers"];
[addValues setObject:whoIsTheUser forKey:@"theUser"];
[addValues saveInBackground];

then i add another button which check if a different user put in the box the same number the first user did, so i'm running a query for this , the code right here :

PFQuery* numQuery = [PFQuery queryWithClassName:@"phoneNumber"];
[numQuery whereKey:@"numbers" equalTo:phoneNumbers];
[numQuery whereKey:@"theUser" notEqualTo:[PFUser currentUser]];
[numQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){


    if(!error)
    {
       // send an alert view for data-has-been-sent 

        UIAlertView *messageForSending = [[UIAlertView alloc]initWithTitle:@"thank you" message:@"the details has been send" delegate:nil cancelButtonTitle:@"okay" otherButtonTitles:nil, nil ];
        [messageForSending show];


        for(PFObject *numObject in objects) {

            // checking how much objects did the query find ...

            if (objects.count > 1 ) {


                NSLog(@"yay we found %lu objects", (unsigned long)objects.count);

                // in the future i will handle those multiply objects somehow :D

            }else{

                // if there's 1 results i know it's going to show this message

             **// HOW CAN I CHECK WHAT'S THE OTHER PFUser ID IS ? AND HOW CAN I MAKE RELATIONSHIP WITH THE CURRENT PFUser ??**

                NSLog(@"yup there is a match");
                //NSLog(@"checking objects %lu", objects.count);
                NSLog(@" object names %@", objects);
                // showing alert message for success

                UIAlertView *successMessage = [[UIAlertView alloc]initWithTitle:@"THERE IS A           MATCH" message:@" we found a match, would u like to talk with him ?" delegate:nil            cancelButtonTitle:@"cancel" otherButtonTitles:@"yes", nil];
                [successMessage show];










            }



        }

    }
    else
    {
  // there's an error so i will show here in the future an UIAleart view for trying again.

        NSLog(@" big error !!!");

    }
}


 ];

so supposed there is 1 match, and both users put the same number ( you can see in the code above i put ** for my question ) . how can I create a Relationship code with the Current PFUser and the new User I found in the Objects ? I want to create a relationship between them two users ID and put it on the database of parse as Friends class. BTW. the code above is working , I created two users and typed 1234 for both of them and it's work :D - now all i got left is connect them both users .

thank's a lot guys ! .

Was it helpful?

Solution

In your second button query, add this line:

[numQuery includeKey:theUser];

This will ensure the user object is fetched together with the result. You can then get this user object with:

PFUser *otherUser = [objects lastObject]; // Assuming there was only 1 user in the result

Now you have both users.

Then, to relate them, you need either a column on each user object with an array of other users who are friends, and update each of these columns on both user objects with the user object of the other user. This column should be an array of pointers.

However, a better approach is to use a separate parse class for friends linking. I assume people can have several such friendships. Maybe that's what your Friends class is for?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top