Write so many code, usually also did not pay attention to this error, because usually very rarely at the same time rewrite setter and getter method, generally speaking, we are probably using lazy loading method, and then rewrite the Getter method, do a non-empty judgment. Then sometimes, depending on the requirements, you want to override both the setter and getter methods of the property. The system will report an error:: Use of undeclared identifier ' _name ';d ID you mean ' name '
MARK: If you don't want to know too much, a straightforward workaround:
Adding a line of code to the @implementation implementation is OK
@synthesize wtname = _wtname;
To explain:
OC initially sets the role of @property and @synthesize:
The role of @property is to define properties and declare Getter,setter methods. (Note: property is not a variable)
The role of @synthesize is to implement attributes, such as the Getter,setter method.
In the case of declaring a property, if you override the Setter,getter method, you need to define the unrecognized variable in @synthesize and use the accessor method of the property for the variable. Such as:
The. h file
Later, because the use of @property ash often, the expression of @synthesize is abbreviated.
From Xcode4.4 after @property has been the monopoly of @synthesize function mainly has three functions:
(1) A private underlined member variable is generated so the subclass cannot be accessed directly, but can be accessed through the Get/set method. So if you want the defined member variable to have the subclass direct access then you can only define the member variable in the. h file, because it defaults to @protected
(2) The implementation of the Get/set method is generated.
When:
The member property declared with @property is equivalent to the auto-generated setter getter method, and if the set and get methods are overridden, the member property declared with @property is not a member property, it is another instance variable, and this instance variable needs to be declared manually. So the error will be reported.
Summary: Be sure to distinguish between attributes and variables, not confused. @synthesize the Declared property = variable. This means that the Setter,getter method of the property acts on this variable.
"Original" IOS rewrite both setter and getter when error: Use of undeclared identifier ' _name ';d ID of ' mean ' name '