• 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: Mutability
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mutability


  • Subject: Re: Mutability
  • From: Ondra Cada <email@hidden>
  • Date: Thu, 22 Nov 2001 23:30:39 +0100

John,

>>>>>> John C. Randolph (JCR) wrote at Thu, 22 Nov 2001 12:05:29 -0800:
JCR> How about:
JCR> @interface NSArray (mutability)
JCR> @implementation NSArray (mutability)
JCR> @implementation NSMutableArray (mutability)

Looks like another nice idea, doomed to fail by the CoreFoundation black
magic (which I am quite inclined to call "a really buggy code" in this case):

=== just have a look ===
123 /tmp> cat q.m
#import <Foundation/Foundation.h>

@interface NSArray (MutabilityTrick)
-(BOOL)isMutable;
@end
@implementation NSArray (MutabilityTrick)
-(BOOL)isMutable {return NO;}
@end
@implementation NSMutableArray (MutabilityTrick)
-(BOOL)isMutable {return YES;}
@end

int main(void) {
id pool=[NSAutoreleasePool new];
id a=[NSArray array];
id b=[NSMutableArray array];

NSLog(@"a %@ %d %d %d",[a class],[a isKindOfClass:[NSMutableArray
class]],[a respondsToSelector:@selector(addObject:)],[a isMutable]);
NS_DURING [a addObject:@""]; NS_HANDLER NSLog(@"a IMMUTABLE!!!"); NS_ENDHANDLER
NSLog(@"b %@ %d %d %d",[b class],[b isKindOfClass:[NSMutableArray
class]],[b respondsToSelector:@selector(addObject:)],[b isMutable]);
NS_DURING [b addObject:@""]; NS_HANDLER NSLog(@"b IMMUTABLE!!!"); NS_ENDHANDLER
return 0;
}
124 /tmp> cc q.m -framework Foundation && ./a.out
2001-11-22 23:25:56.558 a.out[811] a NSCFArray 1 1 1
2001-11-22 23:25:56.559 a.out[811] a IMMUTABLE!!!
2001-11-22 23:25:56.560 a.out[811] b NSCFArray 1 1 1
125 /tmp>
=== end ===

Incidentally, what about checking the code before sending the idea out? ;)
---
Ondra Cada
OCSoftware: email@hidden http://www.ocs.cz
2K Development: email@hidden http://www.2kdevelopment.cz
private email@hidden http://www.ocs.cz/oc


References: 
 >Re: Mutability (From: "John C. Randolph" <email@hidden>)

  • Prev by Date: buddy windows
  • Next by Date: Re: What does P2-->P3 mean ?
  • Previous by thread: Re: Mutability
  • Next by thread: Re: Mutability
  • Index(es):
    • Date
    • Thread