• 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: NSMutableArray morphs itself into an NSArray?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


References: 
 >Re: NSMutableArray morphs itself into an NSArray? (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Re: Encapsulate C struct/toll-free bridging?
  • Next by Date: Re: Encapsulate C struct/toll-free bridging?
  • Previous by thread: Re: NSMutableArray morphs itself into an NSArray?
  • Next by thread: Re: NSMutableArray morphs itself into an NSArray?
  • Index(es):
    • Date
    • Thread