• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
RS: NSObject members class and isMemberOfClass
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RS: NSObject members class and isMemberOfClass


  • Subject: RS: NSObject members class and isMemberOfClass
  • From: Roland Silver <email@hidden>
  • Date: Fri, 7 Sep 2007 04:51:29 -0600

While attempting to find a way to determine if an object ostensibly created as an NSMutableArray really is (I can't change it), I wrote this code:

#import <Cocoa/Cocoa.h>

@interface foo : NSObject {}
@end

@implementation foo
-(void)awakeFromNib {
	NSArray* arr = [NSArray array];
	NSMutableArray* mut = [NSMutableArray array];
	BOOL test1, test2, test3, test4, test5, test6, test7, test8, test9;
	test1 = ([arr isMemberOfClass:[NSArray class]]);
	test2 = ([mut isMemberOfClass:[NSArray class]]);
	test3 = ([arr isMemberOfClass:[NSMutableArray class]]);
	test4 = ([mut isMemberOfClass:[NSMutableArray class]]);
	test5 = ([mut class] == [NSMutableArray class]);
	test6 = ([mut class] == [arr class]);
	test7 = ([NSArray class] == [NSArray class]);
	test8 = ([NSMutableArray class] == [NSMutableArray class]);
	test9 = ([NSArray class] == [NSMutableArray class]);
	NSString* arrStr = [arr className];
	NSString* mutStr = [mut className];
	int mutCount1 = [mut count];
	[mut addObject:@"foo"];
	int mutCount2 = [mut count];
} //end awakeFromNib
@end

When I run it under debugging with a breakpoint on the right-curly line, the values of the variables are:
test1 NO
test2 NO
test3 NO
test4 NO
test5 NO
test6 YES
test7 YES
test8 YES
test9 NO
arrStr NSCFArray
mutStr NSCFArray
mutCount1 0
mutCount2 1


which don't make sense to me.

How are the methods <class> and <isMemberOfClass> supposed to work?
How can I determine if an object ostensibly created as an NSMutableArray really is?



_______________________________________________

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


  • Follow-Ups:
    • Re: RS: NSObject members class and isMemberOfClass
      • From: Fritz Anderson <email@hidden>
    • Re: RS: NSObject members class and isMemberOfClass
      • From: Mike Abdullah <email@hidden>
  • Prev by Date: Re: characters in cocoa
  • Next by Date: Re: Weird crash
  • Previous by thread: Re: characters in cocoa
  • Next by thread: Re: RS: NSObject members class and isMemberOfClass
  • Index(es):
    • Date
    • Thread