Question

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 = "buffo@yahoo.com";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 !

Was it helpful?

Solution

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];

OTHER TIPS

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 :-)

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