Re: boolean into NSDictionary
Re: boolean into NSDictionary
- Subject: Re: boolean into NSDictionary
- From: Art Isbell <email@hidden>
- Date: Mon, 2 Jul 2001 21:31:15 -1000
On Monday, July 2, 2001, at 06:43 PM, Erik M. Buck wrote:
if([boolNumber respondsToSelector:@selector(boolValue)]) {
[myOtherDictionary setObject:[NSNumber numberWithBool:
[boolNumber boolValue]] forKey:@foundActiveObject"];
}
A) -isKindOfClass is almost never what you want given the existence
of -conformsToProtocol: and -respondsToSelector:.
C) Who cares what class boolNumber is as long as it can provide
a boolValue
?
Good points.
B) The if statement was not checking the boolValue but merely
the ability to
provide a boolValue
I don't know what the "if" test criteria really were, but I
assumed that success was defined by the bool value returned
being YES. If the returned bool value was NO or if boolNumber
was nil, then the test failed. So I interpreted the test to be
more than merely the ability to provide a bool value.
D) There is no need to check for nil
I think Java got it right on this one in that nil should not
be considered a boolean value equal to NO. I like to be
explicit in comparing a value to nil. This is more
self-documenting.
But your point is based on assuming that a message to a nil
object always returns nil. This is true for a method that
returns an object, but it isn't guaranteed to be true for a
method that returns a non-object value. I believe that with PPC
code, messages to nil objects will always return a nil value,
but you probably recall that for some other architectures, this
isn't necessarily the case. So if Cocoa ever goes
multiarchitecture, this assumption can bite one's behind.
Art Isbell
Apple iServices Technical Support
http://www.apple.com/iservices/webobjectssupport/
+1-808-591-0836