everyone,
I am new to C / Objective-C and I am doing some exercise in Xcode. Actually it was lecture two from Stanford iTunes.U CS 193 iOS course fall 2013, if somebody's familiar with...
The exercise was asking to create a property for a class called Card.
So in .h file it declares:
@property (strong, nonatomic) NSString *suit;
And in .m file it overrode the getter method:
-(NSString *)suit
{
return _suit ? _suit : @"?";
}
Here it is, I don't understand what this return statement means...
According to the instructor, the getter method prevents the suit property being nil. But I tried to use the following code instead of the code above, it didn't work.
-(NSString *)suit
{
if (!_suit)
return _suit;
else
return @"?";
}
So two questions here:
1,
return _suit ? _suit : @"?";
what does this return statement mean?
2, Why my code did not work?
Appreciated!