Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Boolean = FALSE;

Boolean = FALSE;
Thread Tools
Fresh-Faced Recruit
Join Date: Jun 2000
Status: Offline
Reply With Quote
May 23, 2001, 12:35 PM
 
I am trying to use a boolean in my code to determine if a state has been reached and if I step through the code it appears that it is trying to set the boolean to the correct value but is not setting the correct value. I had some difficulties with setting an int value to an NSNumber value and visa versa but I resolved them by looking at some open source code. Apple's documentation on NSNumber seems to be incomplete. What is the proper way to set a NSNumber that is inited as a bool? Here is my code. The first two statements work but not the third.

NSNumber *uniqueName = [[NSNumber alloc] initWithBool:TRUE];
//1
uniqueName = FALSE;
//2
uniqueName = [NSNumber numberWithBool:FALSE];
//3
uniqueName = [comparisionGroupName isEqualToString:[[groupArray objectAtIndex:0] objectAtIndex:i]];

I have tried [comparisionGroupName isEqualToString:@"string"]; and it still doesn't return that the string is equal.

The other question that I have is that when I call the third line I get a warning during build "assignment makes pointer from integer without a cast" and when I check to see if a boolean is equal using "if (uniqueName == FALSE) " I get the warning "comparision between pointer and integer" Should I be using "if (uniqueName)" or "if (!uniqueName)" instead?
     
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status: Offline
Reply With Quote
May 23, 2001, 12:58 PM
 
A BOOL is a C scalar type, and NSNumber is an object. You can't use objects directly with the C ==, !=, <, >, etc. operators; you need the scalar values.

Also, YES and NO are the values typically used for BOOL, not TRUE and FALSE, though either should work really.

BOOL value = NO;
BOOL value2 = [name isEqualToString:[groupArray objectAtIndex:0]];
NSNumber *boolNumber = [NSNumber numberWithBool:YES];
NSNumber *boolNumber2 = [NSNumber numberWithBool:value2];

if (value2 == [boolNumber boolValue])
{
...
}

if (![boolNumber2 boolValue])
{
...
}

if (value)
{
...
}
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:13 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2