Re: NSMutableArray morphs itself into an NSArray?
Re: NSMutableArray morphs itself into an NSArray?
- Subject: Re: NSMutableArray morphs itself into an NSArray?
- From: Jerry Krinock <email@hidden>
- Date: Mon, 08 Mar 2004 19:16:53 -0800
After reading the great discussion on alloc/init vs. convenience/retain, I
went back to my code and I think maybe I found the problem, getting back to
my original question of: Can an NSMutableArray morph itself into an NSArray?
The first time I use this NSArray, I do this:
crontabLines = (NSMutableArray*)[aString componentsSeparatedByString:
@"\n"];
I think this was might be the cause of the problem. The NSString method
-componentsSeparatedByString "returns an NSArray*". My typecasting does not
change the type, since Objective-C objects "know their own type" and will
not be swayed by my typecasting.
Later in the program, I call a mutating method on crontabLines:
[crontabLines removeAllObjects] ;
and it raises the exception:
*** -[NSCFArray removeAllObjects]: mutating method sent to immutable object
So, I'd like your expert opinions on this:
1) Have I properly explained how the NSMutableArray morphed into an NSArray?
2) Why is it that this exception gets raised on my user's computer, but not
on my computer. We're both running 10.3.2. And supposedly, thousands of
users are running this program, I've got all 5-star ratings on
VersionTracker, and this is the only guy that's triggered the problem!
3) To fix the problem, I replaced the bad line with this:
[crontabLines setArray:[aString componentsSeparatedByString: @"\n"]];
OK?
Jerry
_______________________________________________
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.