• 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: Dustin Voss <email@hidden>
  • Date: Mon, 8 Mar 2004 16:45:55 -0800

On 8 Mar, 2004, at 11:42 AM, Shawn Erickson wrote:

On Mar 8, 2004, at 10:37 AM, Dustin Voss wrote:

The convenience constructors like +array are intended for local variables, not instance variables. To allocate an instance variable, the pattern is:

crontabLines = [[NSMutableArray alloc] init];

The above is kind of a strange comment...

The convenience "constructors" exists, as implied, for your convenience and you can use them any time or place that you want in your code (no local/instance var differentiation). Depending on what you are doing you may have to retain the return objects to get them to live longer then the current auto release pool.

This is true. A better way of making my point would have been to say "...are typically used for..." rather than "...are intended for...".

In the case of instance variables the generally accepted pattern is to use accessor methods to set and get your instance variables (even in init). Those methods should take care of the needed retain (or copy) / release.

Yes, when setting an instance variable, I believe people usually use the accessors that they have written, but to allocate and initialize an array that will last the life of the instance, I believe people simply call alloc and init as I have described. I know I certainly do not write setters for those sorts of instance variables. It seems like an unnecessary method.

In general it is better to use what is most convenient (simple) in your code unless it somehow leads to a performance / resource issue the requires an alternate, potentially less convenient, solution.

It is also good to use patterns that people can recognize. I trying to get across that I think the alloc/init technique is more clear than the convenience/retain technique. Plus, it's one less lines of code, for what little that is worth. :)
_______________________________________________
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.


  • Follow-Ups:
    • Re: NSMutableArray morphs itself into an NSArray?
      • From: Jerry Krinock <email@hidden>
References: 
 >NSMutableArray morphs itself into an NSArray? (From: Jerry Krinock <email@hidden>)
 >Re: NSMutableArray morphs itself into an NSArray? (From: Dustin Voss <email@hidden>)
 >Re: NSMutableArray morphs itself into an NSArray? (From: Shawn Erickson <email@hidden>)

  • Prev by Date: Re: [OT] Apple Developer Certification
  • Next by Date: AppleScript...
  • Previous by thread: Re: NSMutableArray morphs itself into an NSArray?
  • Next by thread: Re: NSMutableArray morphs itself into an NSArray?
  • Index(es):
    • Date
    • Thread