Re: syntax question: question marks
Re: syntax question: question marks
- Subject: Re: syntax question: question marks
- From: Chris Garaffa <email@hidden>
- Date: Sun, 24 Aug 2003 23:39:38 -0400
Hi Mike,
On Sunday, August 24, 2003, at 11:13 PM, <email@hidden> wrote:
So I am trying to get into unit testing with OCUnit and am following
this
stepwise article:
http://www.stepwise.com/Articles/Technical/2002-06-17.01.html
In the article they use this below accessor method which I kind of like
since it allows for a nice way to handle if the value was set to nil. I
know how it works but am looking for someone to help explain the
syntax.
What does a question mark mean? How should I read this?
Thanks.
- (NSString *) firstName
{
return firstName != nil ? firstName : @"";
}
I would read this as "If firstName is not equal to nil, return
firstName. Otherwise, return @""."
It's the same as:
if (firstName != nil) {
return firstname;
} else {
return @"";
}
but much more compact.
--
Chris Garaffa
email@hidden
_______________________________________________
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.