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

General Discussion

HELLLP with frustrating code challenge

I have posted this before but didn't get any help to complete the challenge....so there we go again : Here's the link to the challenge: http://teamtreehouse.com/library/logging-in-and-logging-out. And here's my code:

#import "MainViewController.h"
#import "LoginViewController.h"
#import <Parse/Parse.h>
@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    PFUser *currentUser =[PFUser currentUser];
    if ([currentUser logOut]){
    [self performSegueWithIdentifier:@"showLogin" sender:self];};
};

- (IBAction)logOut:(id)sender {

    [self performSegueWithIdentifier:@"showLogin" sender:self];
}

@end

I have no idea what i m doing wrong and i don't really understand the question, can someone help me ?

2 Answers

It asks for you to have an if statement that performs the segue only if a user is not logged in. So your first line where you get the current user is correct

PFUser *currentUser = [PFUser currentUser]; 

However your if statement conditional is wrong. If the user is logged in, your PFUser object will hold a value, if not, it will be nil. Since we want the segue to be performed when a user is NOT logged in, you could put simply

if (currentUser == nil) { //perform segue here }

Thank you so much ! For some reason i thought [currentUser logOut] would be equivalent to (currentUser == nil)