• 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
Instance or Class Methods?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Instance or Class Methods?


  • Subject: Instance or Class Methods?
  • From: Brian Norwood <email@hidden>
  • Date: Fri, 20 Jun 2008 22:11:45 -0400

This isn't a question of difference; it's about usage.

In many cases, a class has both a "generator" class method (one that returns an initialized instance of the class), as well as an instance method that initializes an existing instance, and the two are otherwise identical in usage. For example, NSString. I can call:

NSString *stuff = [NSString stringWithString:otherStuff];

or

NSString *stuff = [[NSString alloc] initWithString:otherStuff];

The question is this: is there an advantage to one over the other, and why? If so, is this something I should determine on a case by case basis? Is +stringWithString: just a shortcut for +alloc and - initWithString:?
_______________________________________________


Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Instance or Class Methods?
      • From: "Stephen J. Butler" <email@hidden>
  • Prev by Date: Re: Linking with OpenSSL [Resolved]
  • Next by Date: Re: Instance or Class Methods?
  • Previous by thread: Re: Linking with OpenSSL [Resolved]
  • Next by thread: Re: Instance or Class Methods?
  • Index(es):
    • Date
    • Thread