0

I added a UITextView to storyboard that I created a property for and connected in a subview of UIView (called FieldView) in this case. The property was like this

@property (strong, nonatomic) UITextView * instructions;

That FieldView is a property of the viewController

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

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

 self.fieldView.instructions.hidden = YES;

However, xCode's giving 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 in both 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 am trying to do?

Forge
  • 6,538
  • 6
  • 44
  • 64
BrainLikeADullPencil
  • 11,313
  • 24
  • 78
  • 134
  • Is there a property called `instructions` that is defined in your main `FieldView` interface file, i.e. `FieldView.h`? It looks like your first declaration here might unintentionally be conflicting with another property declaration. – bdesham Apr 18 '14 at 16:23
  • @bdesham o i think that's it, I had it first in the .m file and then when I wanted to access it in the view controller, I added it o the .h file, thinking that it, like a method, needed to be in both. oops – BrainLikeADullPencil Apr 18 '14 at 16:25

3 Answers3

15

To resolve your issue you need declare readonly property in .h file and readwrite property in .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
Vlad Papko
  • 13,184
  • 4
  • 41
  • 57
8

I Also got same issue,

If same name property is declared in .h file and you are again declaring it in extension then you will get this error.

So renaming property name will resolve the issue.

Abbas Mulani
  • 703
  • 2
  • 8
  • 19
1

For me, I had to remove one of the properties in AppDelegate.h

Before:

@property (nonatomic, strong) UMModuleRegistryAdapter *moduleRegistryAdapter;
@property (nonatomic, strong) UIWindow *window;

After:

@property (nonatomic, strong) UIWindow *window;
Franco Petra
  • 688
  • 7
  • 18