-2

I have this code, in some .h file:

@interface StatusData :JSONModel <NSCoding>
@property (strong, nonatomic)NSString <Optional> *description;
@end

and I got this warning:

Auto property synthesis will not synthesize property 'description' because it is 'readwrite' but it will be synthesized 'readonly' via another property

which gives me exception in runtime:


Terminating app due to uncaught exception 'NSInvalidArgumentException',

reason: '-[< ClassName> setDescription:]: unrecognized selector sent to instance


is there a way to override the 'description' property to be readwrite ?

Community
  • 1
  • 1
Aviram Netanel
  • 12,633
  • 9
  • 45
  • 69

1 Answers1

1

'description' is a readonly property of NSObject:

@property (readonly, copy) NSString *description; (line 43)

change the property name to something else - That was the easiest solution for avoiding exception.

Anyway, that was only a work-around solution for now until I find a way to override the description property.

Popeye
  • 11,839
  • 9
  • 58
  • 91
Aviram Netanel
  • 12,633
  • 9
  • 45
  • 69
  • 1
    Why do you want to override the `description` property of `NSObject`? I'd recommend having a read of http://stackoverflow.com/questions/5650887/whats-the-harm-of-property-override-in-objective-c to see when it's best to override a property and when it's best to just override it's getter and setter. Personally based on what I see I see no reason for you to override this property and would recommend just using a different property name. – Popeye Mar 11 '15 at 15:33
  • @Popeye thanks for your response. I'll check overriding the setter. basically you are right - choosing a different name is best, but in this case it's a field that comes from the server in a json, and I transform it to a class... – Aviram Netanel Mar 12 '15 at 00:18