• 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
Re: RS: NSObject members class and isMemberOfClass
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: RS: NSObject members class and isMemberOfClass


  • Subject: Re: RS: NSObject members class and isMemberOfClass
  • From: Mike Abdullah <email@hidden>
  • Date: Fri, 7 Sep 2007 12:09:46 +0100

OK, well as it says in the docs, NSArray and NSMutableArray are actually what is known as a class cluster. They are privately subclassed by Cocoa in various ways. e.g. NSCFArray.

However, this shouldn't matter to you, it is an implementation detail. So the question that really matters is why you seem to need to know this? If you ask Cocoa to create a mutable array, it will, and you don't need to know or care about the actual class.

Mike.


On 7 Sep 2007, at 11:51, Roland Silver wrote:

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:
40mikeabdullah.net


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


  • Follow-Ups:
    • Re: RS: NSObject members class and isMemberOfClass
      • From: "Finlay Dobbie" <email@hidden>
References: 
 >RS: NSObject members class and isMemberOfClass (From: Roland Silver <email@hidden>)

  • Prev by Date: Re: Weird crash
  • Next by Date: Re: [Q] Characteristics of different Inter Process Communication mechanism on Mac?
  • Previous by thread: RS: NSObject members class and isMemberOfClass
  • Next by thread: Re: RS: NSObject members class and isMemberOfClass
  • Index(es):
    • Date
    • Thread