Re: isKindOfClass returns null instead of YES or NO
Re: isKindOfClass returns null instead of YES or NO
- Subject: Re: isKindOfClass returns null instead of YES or NO
- From: Kiel Gillard <email@hidden>
- Date: Thu, 21 May 2009 13:45:55 +1000
%@ is a format specifier for printing Objective-C objects.
isKindOfClass and isMemberofClass methods return BOOL values. BOOL
values are not Objective-C objects.
If you want to log a BOOL value, you could use the format specifier %i
as such:
NSLog(@"isKindOfClass: %i", myBool);
With regards to the responding to lowercase string line in code, you
might want to see NSObject's instance method -
(BOOL)respondsToSelector:(SEL)aSelector
Hope this helps.
Kiel
On 21/05/2009, at 1:43 AM, Jeff Decker wrote:
Hello,
I am working through the Stanford iPhone Dev assignments along with
the videos on iTunes. And I'm stuck on the assignment for the first
week. Shoot!
My goal is inspect each object of an array. When I use
isKindOfClass or isMemberOrClass, I do not get an expected YES or NO
but rather a (null).
Here is the relevant code:
NSMutableArray *myArray = [NSMutableArray arrayWithObjects:[NSURL
URLWithString:@"AccountableTreeService.com"], @"Hello World",
[NSProcessInfo processInfo], dictionary, mutableString, nil];
NSEnumerator *enumerator = [myArray objectEnumerator];
id step;
while (step = [enumerator nextObject]){
NSLog(@"========================================");
NSLog(@"Class name: %@", [step className]);
NSLog(@"Is Member of NSURL: %@", [[step class] isMemberOfClass:
[NSURL class]]);
NSLog(@"Is Kind of NSString: %@", [[step class] isKindOfClass:
[NSString class]]);
NSLog(@"Responds to LowercaseString: ");//I'm still working on
this part
}
And here are my unexpected results:
2009-05-20 11:23:31.666 StanfordAssignment1B[18975:10b]
========================================
2009-05-20 11:23:31.667 StanfordAssignment1B[18975:10b] Class name:
NSURL
2009-05-20 11:23:31.668 StanfordAssignment1B[18975:10b] Is Member of
NSURL: (null)
2009-05-20 11:23:31.668 StanfordAssignment1B[18975:10b] Is Kind of
NSString: (null)
2009-05-20 11:23:31.669 StanfordAssignment1B[18975:10b] Responds to
LowercaseString:
2009-05-20 11:23:31.670 StanfordAssignment1B[18975:10b]
========================================
2009-05-20 11:23:31.671 StanfordAssignment1B[18975:10b] Class name:
NSCFString
2009-05-20 11:23:31.673 StanfordAssignment1B[18975:10b] Is Member of
NSURL: (null)
2009-05-20 11:23:31.673 StanfordAssignment1B[18975:10b] Is Kind of
NSString: (null)
2009-05-20 11:23:31.674 StanfordAssignment1B[18975:10b] Responds to
LowercaseString:
2009-05-20 11:23:31.674 StanfordAssignment1B[18975:10b]
========================================
2009-05-20 11:23:31.674 StanfordAssignment1B[18975:10b] Class name:
NSProcessInfo
2009-05-20 11:23:31.675 StanfordAssignment1B[18975:10b] Is Member of
NSURL: (null)
2009-05-20 11:23:31.675 StanfordAssignment1B[18975:10b] Is Kind of
NSString: (null)
2009-05-20 11:23:31.675 StanfordAssignment1B[18975:10b] Responds to
LowercaseString:
2009-05-20 11:23:31.676 StanfordAssignment1B[18975:10b]
========================================
2009-05-20 11:23:31.677 StanfordAssignment1B[18975:10b] Class name:
NSCFDictionary
2009-05-20 11:23:31.680 StanfordAssignment1B[18975:10b] Is Member of
NSURL: (null)
2009-05-20 11:23:31.681 StanfordAssignment1B[18975:10b] Is Kind of
NSString: (null)
2009-05-20 11:23:31.682 StanfordAssignment1B[18975:10b] Responds to
LowercaseString:
2009-05-20 11:23:31.683 StanfordAssignment1B[18975:10b]
========================================
2009-05-20 11:23:31.683 StanfordAssignment1B[18975:10b] Class name:
NSCFString
2009-05-20 11:23:31.683 StanfordAssignment1B[18975:10b] Is Member of
NSURL: (null)
2009-05-20 11:23:31.684 StanfordAssignment1B[18975:10b] Is Kind of
NSString: (null)
2009-05-20 11:23:31.684 StanfordAssignment1B[18975:10b] Responds to
LowercaseString:
Thanks for any help!
Jeff
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden