Haagenti
Haagenti

Reputation: 8144

iOS readonly and retain are mutually exclusive

I want to have a strong readonly property. When I use this code:

@property (strong, nonatomic, readonly) NSString *test;

I get a warning: "Property attributes 'readonly' and 'retain' are mutually exclusive". How can I solve this warning?

Upvotes: 3

Views: 230

Answers (1)

Wain
Wain

Reputation: 119031

Create a property in your continuation category which redefines the variable as readwrite:

@property (strong, nonatomic, readwrite) NSString *test;

Now, publicly the property is read only, but privately you can write it. The compiler will generate the methods you need and allow you to call them.

Upvotes: 3

Related Questions