• 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: A quick one: Passing a reference/pointer to NSString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A quick one: Passing a reference/pointer to NSString


  • Subject: Re: A quick one: Passing a reference/pointer to NSString
  • From: Ken Thomases <email@hidden>
  • Date: Tue, 22 Jul 2008 21:25:12 -0500

On Jul 22, 2008, at 9:14 PM, Ken Thomases wrote:

Alternatives to consider:

*) Have the method return an NSArray* containing the strings
*) Have the method return a struct which has two NSString* fields
*) Have a method such as:

- (void) getGreeting:(NSString**)greeting andAdressee: (NSString**)addressee;

That is, if you're going to write a get-style method, probably better to have it supply both outputs through by-reference parameters than to supply one via by-reference parameter and another via return value.

More alternatives that I forgot to list:

*) Have the method return an NSDictionary* with keys for accessing the two strings
*) Have separate methods:


-(NSString*) greeting;
-(NSString*) addressee;

*) The usual justification for returning two values from one method is that the two are closely interrelated. It maybe doesn't make sense for them to exist in isolation from one another. (The trivial examples discussed don't illustrate this.) In such a case, that might be a design clue that you need a separate class to represent whatever single conceptual idea spans the two tidbits of information. So, you might want a custom class which represents the single concept which has two (or more) properties. Then, -foo (no colon) would return an instance of that class.

Cheers,
Ken
_______________________________________________

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


References: 
 >Re: A quick one: Passing a reference/pointer to NSString (From: Jeff Brown <email@hidden>)
 >Re: A quick one: Passing a reference/pointer to NSString (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: A quick one: Passing a reference/pointer to NSString
  • Next by Date: Re: A quick one: Passing a reference/pointer to NSString
  • Previous by thread: Re: A quick one: Passing a reference/pointer to NSString
  • Next by thread: NSConnection Issue
  • Index(es):
    • Date
    • Thread