Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to search parse DB in iOS app

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 257
    Comment on it

    No separate method is provided to do search in Parse document. Following code can be used to search a column .

     PFQuery *query = [PFUser query];
        [query whereKey:@"username" hasPrefix:searchText.lowercaseString];
        [query whereKey:@"objectId" notEqualTo:[[PFUser currentUser] objectId]];
        [query findObjectsInBackgroundWithBlock:^(NSArray *result, NSError *error){
            callback(result, error);
        }];
    

    // Above code is searching for users(other than the logged in user) based on their username

    Above, before providing searchText to query I am converting it to lower case as parse does not support case sensitive search. So, either save usernames as lower case string or as upper case string. Then only this search method can be used.

    One more condition is provided in PFQuery that can help in search. "containsString" can also be used for search as follow:

    PFQuery *query = [PFUser query];
        [query whereKey:@"username" containsString:searchText.lowercaseString];
        [query whereKey:@"objectId" notEqualTo:[[PFUser currentUser] objectId]];
        [query findObjectsInBackgroundWithBlock:^(NSArray *result, NSError *error){
            callback(result, error);
        }];
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: