ios - why isn't lazy instantiation used in every getter -
Paul Hagerty likes to use lazy instant in Stanford Courses. For example, he makes a personal announcement of
@property (strong, non-creative) (NSARRA *) card and then it's a Gator's An introduction to use
- (NSArray *) card {if (! _card) _cards = [[NSARROLO] Init] return _cards; } I am good with that what I do not get, though it is that Paul at any other time declares a public suit for a public card: < pre> @property (strong, nonatomic) NSString * suite; But in the implementation he does not perform this lazy immediate. So I do not understand where the suit strings are allotted intus? (Suit is an indicator for an NSString-object that should have a location in the heap)
#import "PlayingCard.h" @implementation PlayingCard @ synthesize suit = _suit; - (Zero) SetSat: (NSSTING *) Suit {if ([[[["" a ?? £ ¸¸ ?? ", @" one ?? i ?? ", @" a ?? ¥ ¸¸¸ ?? ", @" One â "ï ¸¸¸¸¸ ??"] includes the object: suit]] {_suit = suit; }} - (NSString *) Suite {Return _suit? _suit: @ "?"; } @end
when you ask for a card example There is no additional information required (i.e. there is no required parameter). Just instantize a playing card and return it. A suits , on the other hand, can be one of the four options, so someone needs to set that somewhere to note that this issue actually comes from lazy initialization It is free to do so with the fact that it is expected that the suite is expected to start with a user-parameter value There is a way of saying lazy initialization, " As long as I ask for it make an example of this object Do not be rash. " But in the case of suits , you do not want to make the string until the user provides it.
Comments
Post a Comment