Does the following function return YES
if object != nil
?
- (BOOL)boolForObject:(id)object {
return (BOOL)object;
}
I've tested with object = [[NSObject alloc] init]
but got mixed results.
A pointer is larger than a BOOL, so when you cast it will truncate and take only the 8 least significant bits of the pointer and make it a BOOL. If those bits all happen to be zero then that is equivalent to NO.
So to answer your question, no it does not (well sometimes it will depending on the pointer value)
Here's an example with using Xcode 5.1.1 on 32 bit architecture:
void* p = (void*)0xfeeeff00;
BOOL b = (BOOL)p;
NSLog(@"p=%08x (%lu), b=%08x (%lu)", (uint32_t)p, sizeof p, (uint32_t)b, sizeof b);
It prints out:
p=feeeff00 (4), b=00000000 (1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With