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

Re: Mutable class problems


  • Subject: Re: Mutable class problems
  • From: Ondra Cada <email@hidden>
  • Date: Tue, 25 Jun 2002 14:10:26 +0200

On Tuesday, June 25, 2002, at 10:50 , Marco Scheurer wrote:

I seem to remember a conversation where checking for immutablity was bound to fail in some obscure way.

One could always define the method -(BOOL) isMutable in categories of NSDictionary, NSMutableDictionary, NSArray ...

One could -- in a decent OpenStep implementation, which Cocoa is not, alas.
Due to a design of CoreFoundation which I personally call a *very grave* bug it would not work, though -- I am afraid you haven't tried:

40 /tmp> cat q.m
#import <Foundation/Foundation.h>

@interface NSArray (Test)
-(BOOL)isMutable;
-(void)doSomething;
@end
@implementation NSArray (Test)
-(BOOL)isMutable { return NO; }
-(void)doSomething { NSLog(@"Doing something the immutable way"); }
@end
@implementation NSMutableArray (Test)
-(BOOL)isMutable { return YES; }
-(void)doSomething { NSLog(@"Doing something the mutable way"); }
@end

int main() {
id p=[NSAutoreleasePool new];
id a=[NSArray array],b=[NSMutableArray array];
NSLog(@"a %d, b %d",[a isMutable],[b isMutable]);
NSLog(@"And this is even worse bug!!!!");
[a doSomething];
[b doSomething];
[p release];
return 0;
}
41 /tmp> cc -framework Foundation q.m && ./a.out
2002-06-25 14:07:06.218 a.out[1273] a 1, b 1
2002-06-25 14:07:06.219 a.out[1273] And this is even worse bug!!!!
2002-06-25 14:07:06.219 a.out[1273] Doing something the mutable way
2002-06-25 14:07:06.220 a.out[1273] Doing something the mutable way
42 /tmp>

I've bumped into this weirdness shortly after I had moved from the last decent OpenStep implementation (which was the YellowBox of Mac OS X Server 1.x) to the current mess; exchanged some messages with Chris Kane just to learn that this havoc is -- from Apple's point of view -- *THE RIGHT WAY HOW IT SHOULD WORK*.

Deep sigh.
---
Ondra Cada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Mutable class problems (From: Marco Scheurer <email@hidden>)

  • Prev by Date: Re: Mutable class problems
  • Next by Date: Re: Escaping spaces in paths
  • Previous by thread: Re: Mutable class problems
  • Next by thread: Re: Mutable class problems
  • Index(es):
    • Date
    • Thread