The attribute should be readwrite, while its primary should be read-only

I added a UITextView to the storyboard that in this case I created a property and connected to the UIView subtitle (called FieldView). The property was like this:

@property (strong, nonatomic) UITextView * instructions; 

That FieldView is a property of viewController

 @property (strong, nonatomic) IBOutlet FieldView *fieldView; 

When I wanted to hide the UITextView * instructions with the code in the viewController, I declared a property in the .h file, so that I could eventually do this when the button was clicked

  self.fieldView.instructions.hidden = YES; 

However, xcode gives me an error

  illegal redeclaration of property in class extension FieldView, attribute must be readwrite while its primary must be readonly 

When I added readwrite to the .h and .m files

 @property (weak, nonatomic, readwrite) IBOutlet UITextView *instructions; it said `perhaps you intended this to be a readwrite redeclaration of a readonly public property 

What is the correct way to do what I'm trying to do?

0
source share
2 answers

To solve the problem, you need to declare the readonly property in the .h file and readwrite in the .m file:

 //FieldView.h @interface FieldView @property (nonatomic, readonly, strong) UITextView *instructions; @end // FieldView.m @interface FieldView() @property (nonatomic, readwrite, strong) IBOutlet UITextView *instructions; @end 
+8
source

I have the same problem too

If the same name is declared in the .h file and you declare it again in the extension, you will get this error.

Therefore, renaming the property name will solve the problem.

+5
source

Source: https://habr.com/ru/post/1232468/


All Articles