0

I have this code:

- (BOOL)logInViewController:(PFLogInViewController *)logInController shouldBeginLogInWithUsername:    
(NSString *)username password:(NSString *)password
{
    NSLog(@"anything");
    return false;
}

and if I run it then I get this bug in some assembly code: "Thread 1: EXC_BAD_ACCESS (code = 2, address = 0x1a). If I change the code to:

- (BOOL)logInViewController:(PFLogInViewController *)logInController shouldBeginLogInWithUsername:    
(NSString *)username password:(NSString *)password
{
    NSLog(@"anything");
    return NO;
}

I do not get that bug. However, in both cases nothing is printed to the terminal. This doesn't make sense to me because if that code causes the bug, then shouldn't that area be read by the computer, and therefore the NSLog should be called? So confused. So I guess my question is why isn't anything printed to the terminal and also why does the change to NO make the bug go away? I wouldn't think their difference would cause the bug? Why does it?

Edit: Really sorry y'all. The above code had nothing to do with my error. Apologies.

Casey
  • 41,449
  • 7
  • 95
  • 125
  • First check whether this Method is getting called or not? Because in either case it has to Log the text "anything". – hpp Jan 29 '14 at 05:23
  • I don't understand. The way I check if methods get called is with an NSLog. – user3139679 Jan 29 '14 at 05:26
  • hi, not getting what you want to say, please explain. – hpp Jan 29 '14 at 05:29
  • What actions were you suggesting I take in your first comment? – user3139679 Jan 29 '14 at 05:32
  • What i mean to say is whether you return false or return NO in either case it should print "anything". Put a break point on this method and try to debug it and make sure that its getting called. – hpp Jan 29 '14 at 05:35
  • I already tried breaking on that method (it is not called), I just don't understand why given that a method is not called and there are no compiler errors, how text in that method block can cause a crash. – user3139679 Jan 29 '14 at 05:38
  • So, it means there is some problem from where you are calling this method. Please check it out or Put that source code here so that somebody can help you. – hpp Jan 29 '14 at 05:40

2 Answers2

0

First thing About this Question :

difference between YES and true and NO and false

The TRUE macro is only provided as backwards-compatibility with C language Code as the Objective-C is designed to be a strict super-set of C. So TRUE and YES both are same.

Possible Duplicate Question

Community
  • 1
  • 1
Buntylm
  • 7,345
  • 1
  • 31
  • 51
0

I don't know what is exact problem butnot major different but there are two type of boolean in objective-c

1) BOOL
2) bool

So BOOL can contain values other than YES and NO. and bool can contain values other than TRUE and FALSE.

For most people this is an unnecessary concern, but if you really want a boolean it is better to use a bool. I should add: the iOS SDK generally uses BOOL on its interface definitions, so that is an argument to stick with BOOL.

//These will all print "1"
NSLog(@"%d", true == true);
NSLog(@"%d", TRUE == true);
NSLog(@"%d", YES == true);
NSLog(@"%d", true == TRUE);
NSLog(@"%d", TRUE == TRUE);
NSLog(@"%d", YES == TRUE);
NSLog(@"%d", true == YES);
NSLog(@"%d", TRUE == YES);
NSLog(@"%d", YES == YES);

NSLog(@"%d", false == false);
NSLog(@"%d", FALSE == false);
NSLog(@"%d", NO == false);
NSLog(@"%d", false == FALSE);
NSLog(@"%d", FALSE == FALSE);
NSLog(@"%d", NO == FALSE);
NSLog(@"%d", false == NO);
NSLog(@"%d", FALSE == NO);
NSLog(@"%d", NO == NO);


//These will all print "0"
NSLog(@"%d", false == true);
NSLog(@"%d", FALSE == true);
NSLog(@"%d", NO == true);
NSLog(@"%d", false == TRUE);
NSLog(@"%d", FALSE == TRUE);
NSLog(@"%d", NO == TRUE);
NSLog(@"%d", false == YES);
NSLog(@"%d", FALSE == YES);
NSLog(@"%d", NO == YES);

NSLog(@"%d", true == false);
NSLog(@"%d", TRUE == false);
NSLog(@"%d", YES == false);
NSLog(@"%d", true == FALSE);
NSLog(@"%d", TRUE == FALSE);
NSLog(@"%d", YES == FALSE);
NSLog(@"%d", true == NO);
NSLog(@"%d", TRUE == NO);
NSLog(@"%d", YES == NO);

Got from Is there a difference between YES/NO,TRUE/FALSE and true/false in objective-c?

Community
  • 1
  • 1
iPatel
  • 46,010
  • 16
  • 115
  • 137