Another pertinent use of @property design question

This is a sequel to Prevent @property-itis .

UIWebView has the following property declarations:

@property(nonatomic,readonly,getter=canGoBack) BOOL canGoBack;
@property(nonatomic,readonly,getter=canGoForward) BOOL canGoForward;

      

UIScrollView has the following meanings:

@property(nonatomic) BOOL canCancelContentTouches;

      

However, UIResponder has

- (BOOL)isFirstResponder;
- (BOOL)canBecomeFirstResponder;
- (BOOL)canResignFirstResponder;

      

Is the case of UIResponder where they should have been declared as properties but for whatever reason they weren't?

Or is this a case where declaring them as properties was inappropriate? If inappropriate, why?

+1


source to share


3 answers


My best guess is that UIResponder is designed to conform to NSResponder, which of course was designed before Objective-C 2.0 injected properties. Why UIWebView doesn't do the same with regard to WebView I don't know. I would expect the properties in Cocoa to be a little schizophrenic in this way for some time, and I won't go into too much of it while reviewing your own code.



+1


source


Synthesized properties define how properties are accessed. Whether using synthesized properties or not, this is a design decision, since properly used getter and setter methods provide identical functionality.



As long as this method can be properly implemented using the available property attributes, there is no reason why they cannot be rewritten to do so.

+1


source


The property should represent, intuitively, if not exactly, some sort of storage mechanism for your class - be it an ivar declared in yours @interface

or something synthesized at runtime. The act of calling a method such as canBecomeFirstResponder

does not necessarily have to request a class for a storage engine that contains a trivial one BOOL

, but rather causes some chain of events to fire, which requests the responder tree. That is, there is no firstResponder

ivar as the value of any of these methods cannot be stored in the cache and must be determined at runtime.

0


source







All Articles