Re: NSMutableArray morphs itself into an NSArray?
Re: NSMutableArray morphs itself into an NSArray?
- Subject: Re: NSMutableArray morphs itself into an NSArray?
- From: Peter Maurer <email@hidden>
- Date: Tue, 9 Mar 2004 16:35:01 +0100
NSMutableArray* crontabLines ;
...
// but the following mistake morphs it into an immutable array
// since -componentsSeparatedByString returns an NSArray*:
crontabLines =
(NSMutableArray*)[aString componentsSeparatedByString: @"\n"];
There's no "morphing" taking place. You declared your pointer
"crontabLines" and the resulting pointer from [NSString
componentsSeparatedByString:] as being pointers to NSMutableArrays, but
that information is nearly irrelevant. They're all just pointers -- if
that weren't the case, you couldn't use "id" instead of "NSArray *".
These code snippets all do the same thing...
id crontabLines = [aString componentsSeparatedByString: @"\n"];
NSArray *crontabLines = [aString componentsSeparatedByString: @"\n"];
NSMutableArray *crontabLines = (NSMutableArray *)[aString
componentsSeparatedByString: @"\n"];
NSButton *crontabLines = (NSImage *)[(NSWindow *)aString
componentsSeparatedByString: (NSMutableDictionary *)@"\n"];
The only change you'll see is a different number of warnings when
building your project. Regards,
Peter.
PS: Sorry if this was already explained, but I sort of overlooked this
thread up to now.
PPS: I second Allan's explanation on why your code works for most users.
___
http://www.petermaurer.de/butler
_______________________________________________
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.