Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Fabio Floris
526 PointsHow to Remove PFUser Current User from List Total User?
Hello everyone I have followed with great enthusiasm and satisfaction tutorial on PFRelation ... I wanted to ask you something if you can ... How do I delete from the list the total number of users CurrentUser? I would avoid that the report will also be made with oneself: D Thank you all and congratulations ... Finally some good tutorials
Alex Hedley
16,381 PointsCurrently the list of users includes all users. This includes yourself. This isn't necessary as you're unlikely to send yourself a pic or video. I guess they are after a way of removing [PFUser Current User] from this list.
2 Answers
Ben Jakuben
Treehouse TeacherGreat question! I should have added this to the project. I left the current user in the list because it's super helpful for testing purposes.
What you are looking for is a way to query the Users class and get users where their ID does not equal the ID of the current user. If you are familiar with using SQL to access databases, then you'll recognize the "WHERE" clause. Basically, what we're after in plain English is:
"select all the users from the Users class where the user ID is not the current user ID"
Our code currently does the first part: "select all the users from the Users class"
We can add a where clause using one of Parse's whereKey method calls. Specifically, we want to use whereKey:notEqualTo:.
We can add this to our query object before we call findObjectsInBackgroundWithBlock.
Hopefully that's enough to show you what you need to do. I have working code I can add if you'd like, but it'll probably be more meaningful for you if you work it out using the Parse documentation. One note: don't forget to move the line that sets self.currentUser above the PFQuery stuff!
self.currentUser = [PFUser currentUser];
PFQuery *query = [PFUser query];
...
Fabio Floris
526 PointsHello to all!! Ben! It is precisely what I wanted to hear, I apologize to everyone for my bad english: (
I followed what you suggested but I get no results ... My tableView is completely empty and the NSLog gives me this error:
10/21/2013 21:17:35.080 Unigo! [24355: a0b] Error: Error Domain = Parse Code = 102 "The operation could not be completed. (Parse error 102.)" UserInfo = 0x98b6360 {code = 102, error = username contains string values ??but got a *} {_USER
code = 102;
error = "username contains string values ??but got a * _USER";
}
This is the code that I used and I file.h
@ property (nonatomic, strong) PFUser * CurrentUser;
Where am I doing wrong?
(void)viewDidLoad
{
[super viewDidLoad];
self.TableView.delegate = self;
self.TableView.dataSource = self;
FFSearchBar.delegate = self;
self.CurrentUser = [PFUser currentUser];
PFQuery *query = [PFUser query];
[query whereKey:FF_USER_USERNAME notEqualTo:self.CurrentUser];
[query orderByAscending:FF_USER_NOMECOGNOME];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error) {
NSLog(@"Error: %@ %@", error, [error userInfo]);
} else {
NSLog(@"%@", objects);
self.Utenti = [[NSMutableArray alloc] init];
for (PFObject *object in objects) {
[self.Utenti addObject:object];
}
[self.TableView reloadData];
}
}];
// Do any additional setup after loading the view.
}
Fabio Floris
526 PointsPerfect Guys .. then I found the method ... In layman's terms is exactly as said BEN, so it is right to use notEqualTo in the query but it should be associated with the string that we want to remove from the query
Do not pay too much attention to the constants: D
I hope this can help other people :)
PFQuery * query = [PFUser query];
[query whereKey: FF_USER_NOMECOGNOME notEqualTo: [[PFUser currentUser] objectForKey: FF_USER_NOMECOGNOME]];
[query orderByAscending: FF_USER_NOMECOGNOME];
[query findObjectsInBackgroundWithBlock: ^ (NSArray * objects, NSError * error) ....
Ben Jakuben
Treehouse TeacherSo glad you got it! As you said, the trick is to get the object_id of the current user. Carry on! :)
Fabio Floris
526 PointsThanks Ben! it is also about your tutorial ... I unfortunately do not know much English are Italian and it is very difficult for me to follow the tutorial ... I focus a lot on the actions you do in the tutorial ... Anyway congratulations for what you do .. I have learned many things from you and are very pleased with all of this .. Thanks so much for the help you give ... Keep doing more and more specific tutorial also parse.com, many people use it! You are wonderful! : D
Ben Jakuben
Treehouse TeacherYour English is pretty good, and far better than my Italian! I'm glad to hear you appreciate the tutorials and I think it's amazing that Treehouse is reaching students around the world. Hopefully we can find a way to translate our stuff into other languages in the future.
Fabio Floris
526 PointsIt would be fabulous Ben! ... If I can be helpful in something are available: D I also think that bore you a little more with other future questions I am doing my project in xcode and push notification and badge number directly created by a label, I'm going crazy: D
Ben Jakuben
Treehouse TeacherWe are happy to help if we can! If you have questions about Push Notifications, post new ones here in the Forum and Amit or I or other students can try to help. :)
Fabio Floris
526 PointsI was going to just post a new post now ... I wanted to have information on how to submit a project on the ScopeBar Parse.com ...
Amit Bijlani
Treehouse Guest TeacherAmit Bijlani
Treehouse Guest TeacherCan you please clarify what you mean by: " How do I delete from the list the total number of users CurrentUser?" Do you mean that you want to see the total number of users? Or update the count?