0

I will try to explain myself as best as I can. My app has a login & sign Up using the Parse API . after signing or logging the User see a page with a Button and a Text Field which he can write Numbers in it , let's say he write , for example: 1234.

the button job is to save the data from the text field Now i'm sure my Button method isn't the best way, but it's work :-)

NSString *whoIsTheUser = [PFUser currentUser];
NSString *phoneNumbers = phoneNumberField.text ;



NSString *fullData = [NSString stringWithFormat:@" %@ , %@", whoIsTheUser, phoneNumbers];
NSLog(@" %@, %@ ", whoIsTheUser, phoneNumbers);

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

So now what i'm having is the data saved to parse site under class of Numbers (forKey:@"numbers") and it's look like this :

 <PFUser:hqExhaYaIN:(null)> {email = "[email protected]";username = buffo;} ,  1234

what I'm trying to do is to add another button which going to check if theres another user who wrote the same numbers and then send an alert or do something . I have tried to read about the PFQuery but didn't find any solution. is it even possible to run Query in the classes name ? or maybe theres another way to do it ( within the parse site ) ? thank you so much for any suggestion !

2 Answers 2

0

It looks like you need to split up fullData in your parse objects and do something like this

PFQuery* numQuery = [PFQuery queryWithClassName:@"phoneNumber"];
[numQuery whereKey:@"numbers" equalTo:phoneNumbers];
[numQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error)
{
     if(!error)
     {
        for(PFObject *numObject in objects)
        {
          //Do what you need to do here
        }
     }
     else
     {
         //handle error
     }
}

EDIT - this means you would save your PFObjects like this

PFObject *addValues= [PFObject objectWithClassName:@"phoneNumber"];
[addValues setObject: phoneNumbers forKey:@"numbers"];
[addValues setObject: whoIsTheUser forKey:@"theUser"];
[addValues saveInBackground];
Sign up to request clarification or add additional context in comments.

3 Comments

you are right, the split data works perfect , now I can see a column with the user ID . BUT, the if statement is not working. i need to create an If statement with the Current User ID, which means if the current user type 1234, so the search query will skip what the current user typed, so it won't show a match. I still don't understand how your if statement is correct. thank you for any help ! P.S ( again my main concept that if user1 type 1234 and then user2 typed 1234 so user2 will see an UIAlert.
then in your query, you should limit the results to those that aren't the user. parse.com/docs/ios_guide#queries-constraints/iOS
well i'll take that as an answer since it's help me
0

i hope it's going to help someone like it's helps me , if you want to query for info without the user info use those lines

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

all I had to do is add notEqualTo and CurrentUser :-)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.