• 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: syntax question: question marks
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >syntax question: question marks (From: <email@hidden>)

  • Prev by Date: syntax question: question marks
  • Next by Date: Re: syntax question: question marks
  • Previous by thread: syntax question: question marks
  • Next by thread: Re: syntax question: question marks
  • Index(es):
    • Date
    • Thread