Re: A quick one: Passing a reference/pointer to NSString
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