[MacRuby-devel] Immutable foundation objects

Thibault Martin-Lagardette thibault.ml at gmail.com
Mon Feb 15 03:18:15 PST 2010


Hi Erik!

NSArray, when instanciated, becomes the equivalent of a ruby array, see for yourself with macirb:
>> a = NSArray.alloc.init
=> []
>> a.class
=> Array

However, you are right, it might need to become frozen, because otherwise, this happens:
>> a << "MacRuby"
2010-02-15 11:57:08.766 macruby[98594:903] -[__NSArray0 addObject:]: unrecognized selector sent to instance 0x20022e820
uncaught Objective-C/C++ exception...
2010-02-15 11:57:08.795 macruby[98594:903] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArray0 addObject:]: unrecognized selector sent to instance 0x20022e820'

And this is not really what we want :-)

Laurent, what were your plans about that? Should we modify NSArray.m and use an NSMutableArray, or should we freeze NSArray instances?

-- 
Thibault Martin-Lagardette



On Feb 14, 2010, at 16:29, Erik Österlund wrote:

> Hello.
> 
> This is just a thought, but shouldn't for instance NSArray.alloc.init.frozen? return true, as it is immutable and cannot be changed? It is like a frozen version of NSMutableArray, isn't it?
> It's a bit confusing when asking an immutable Foundation object if it is frozen, and it says no...
> On the other hand, I suppose it's possible to create categories that add behavior that somehow modifies the object.
> 
> Any thoughts on this?
> 
> Thanks.
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20100215/21790110/attachment.html>


More information about the MacRuby-devel mailing list