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

james white
78,399 PointsCode challenge: Logging in and Logging out
This is the challenge link:
I tell you honestly I was really scared of this Ribbit ("Build a Self-Destructing Message iPhone App") course.
Not only is it listed as 7 hours to complete (can you believe it).
But from having done almost all the other iOS Objective-C courses first I can tell you that:
1.) The Objective-C courses need helps!
See this forum thread: https://teamtreehouse.com/forum/completely-lost
...where Amit even admits (towards the end of the thread):
"We are aware of the issues in the Objective-C Basics course and it's due for a re-write."
2.) And...this one Ribbit self destructing course (in particular) has more BAD (misinformation) threads than just about any other course Treehouse offers...
I am in to the heart (middle) of the course where I came across this challenge (linked to above).
.............
One of the question things (that causes a lot of confusion --at least for me), is that you don't have an ".h" file and a ".m" files (or two pairs of these files..
In this challenge you have two ".m" files ("MainViewController.m" and "LoginViewController.m").
So where's the corresponding .h files --who knows?!
Even worst, the sequence of challenge questions has you switching back and forth between them (I know -- total craziness, indeed).
I'm going to go through the questions and try to explain them:
Challenge Task 1 of 4
Let's implement another login/logout system. In this view controller, start by importing the Parse header file (Parse/Parse.h).
What is "this view controller"?
Hopefully you guessed (only by the fact that the challenge starts out with MainViewController.m files tab selected) that this line goes in MainViewController.m, and NOT LoginViewController.m):
#import <Parse/Parse.h>
......................................................
On to the next question:
Challenge Task 2 of 4
In viewDidLoad we see that the LoginViewController is presented automatically. Set the 'currentUser' variable using the appropriate method from the
PFUser class. Then use that variable in an if statement to only perform the segue to LoginViewController if no user is logged in.
Now I'm in total confusion mode --it mentions 'LoginViewController' in the question,
...so does mean the needed code goes in 'MainViewController.m' (which we already have selected)?
..or (perhaps) do we have to switch to the 'LoginViewController' file tab to write some code.
Hmmm...
Anyway, with the second part of the challenge the question-able forum thread answers begin.
Here's one: https://teamtreehouse.com/forum/code-challenge-logging-in-ribbit-app
Neither of Aaron Ackerman's code sets is Germaine (will pass) and the guy is listed as "Mod" (for moderator.
Here's another one:
https://teamtreehouse.com/forum/logging-in-and-logging-out-code-challenge-2
In this thread cameron (the non-moderator) actually provides more helpful code snippet [IMHO], then the moderator Aaron Ackerman's code.
However, let's not dwell.
Here's the MainViewController.m files code that passes Challenges 1, 2, and 4:
#import "MainViewController.h"
#import "LoginViewController.h"
#import <Parse/Parse.h>
@implementation MainViewController
- (void)viewDidLoad {
[super viewDidLoad];
PFUser *currentUser;
currentUser = [PFUser currentUser];
if (currentUser) {
}
else {
[self performSegueWithIdentifier:@"showLogin" sender:self];
}
}
- (IBAction)logOut:(id)sender {
[PFUser logOut];
[self performSegueWithIdentifier:@"showLogin" sender:self];
}
@end
Now on to the the part of the challenge that really seems to confuse people:
Challenge Task 3 of 4
Now switch to LoginViewController.m. Blocks can also be declared and passed around as variables, as we can see in the existing code below. This
code declares a block named loginHandler on line 17. In the login method (where it says "Add your code below!"), add a call to the PFUser class
method logInWithUsernameInBackground:password:block:. Use @"test" as the 1st and 2nd parameters. Then pass in loginHandler as the 3rd parameter.
At least the question *finally tells us outright we are switching file tabs to 'LoginViewController.m'.
So (if nothing else) we finally know where the code is supposed to go that we are expected to produce.
If (heaven forbid) the need code can't be accessed off the top of your head (or after hours and hours of seeing parse errors), you might end up turning to the forum for help with challenge 3 of 4.
Here's what you would encounter: https://teamtreehouse.com/forum/code-challenge-logging-in-and-logging-out-3-of-4
If you read the thread carefully most of it is about 2 of 4, not 3 of 4, but no one in the thread seems willing to post what it was that they actually got to pass.
In this thread, there is no valid passing code for 3 of 4 as well: https://teamtreehouse.com/forum/selfdestructing-code-challenge-stage-2-help
Hopefully you eventually come across this thread where the moderator Aaron Ackerman's code was helpful: https://teamtreehouse.com/forum/code-challenge-help-totally-stuck
However, just for completeness, here's the full code for LoginViewController.m that will pass:
#import "LoginViewController.h"
#import "UIAlertView.h"
#import <Parse/Parse.h>
@implementation LoginViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)login:(id)sender {
// This is an example of how to declare a block named loginHandler. It starts with a
// return type, then the name of the block with a special syntax for naming. The next
// set of parentheses hold the parameters and their types. Then assigning the block
// on the right side looks just like how we defined it in the video (carat with the
// same parameters in parentheses).
void (^loginHandler)(PFUser *user, NSError *error) = ^(PFUser *user, NSError *error) {
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry!"
message:@"Error logging in."
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
else {
[self.navigationController popToRootViewControllerAnimated:YES];
}
};
// Add your code below!
[PFUser logInWithUsernameInBackground:@"test" password:@"test" block:loginHandler];
}
@end
.................................
..which brings us (at last) to the final part of the challenge:
Challenge Task 4 of 4
Finally, switch back to MainViewController.m. In the logOut method, before the Login view controller segue is performed, add a call to Parse to log out the current user. Hint: Use the PFUser class method
The final code for that goes in the MainViewController.m file tab, I've already pasted in above, but it left me sorta thinking:
----- "would it have been so wrong to just stick with MainViewController.m for parts 1,2,3 of 4 than switched to LoginViewController.m to finished the challenge by asking the question about what code was need there"
If not...then it would have saved multiple "switchings" and (possibly) avoided some confusion.
Oh, and here's the forum thread that seems to come up most frequently for part 4 of the challenge:
https://teamtreehouse.com/forum/code-challenge-logging-in-and-logging-out-4-of-4
I guess the answer engine issue got fixed -- but did Masao ever get rewarded with an Exterminator badge?
Inquiring minds are left wondering...but hopefully anyone reading this thread will be one step further past one of the most difficult (or at least non-trivial) objectives for this long course.
Good luck on the rest. : ) ☺ (ツ)
(..and, here's an interesting if totally spurious question --why doesn't the forum markup include even a limited set of emoticons?)
(..and, here's an interesting if totally spurious question2 --why doesn't the forum markup lightbox dialog actual LIST the possible languages that can used after the three ticks).
I know its totally LAZY for me to want to just copy and paste them simply using mouse highlighting, (rather than have to type them in) but there it is..I admit it. <shrug:>
1 Answer

Travis Deaton
6,871 PointsBravo! I found this challenge to be the most confusing and absurd thus far. So, thank you. I'm sure I am not alone in saying that you outlined our frustrations with this code challenge exceptionally well. Well done!