Xcode 6.1: Need a 'mutableCopy' property qualifier for mutable objects
| Originator: | kusterer | ||
| Number: | rdar://19114187 | Date Originated: | 02-Dec-2014 02:59 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 6.1 (6A1052d) |
| Classification: | Security | Reproducible: | Always |
Often one has a class that obtains an object via a property and internally mutates it. The naïve approach would be: @interface MyClass @property (copy) NSMutableString* targetString; @end However, this is invalid because this calls -copy on the NSMutableString, producing an NSString, which is then assigned to the ivar (this should really be a compile-time error, but is sadly only detected at runtime). However, it's not that important, as it also violates encapsulation. What the designer probably wanted to do was make the object immutable to the outside, but mutable internally: @interface MyClass @property (copy) NSString* targetString; @end @interface MyClass () @property (mutableCopy) NSMutableString *targetString; @end It would be cool if you could support this common pattern: 1) If a property is declared as "copy" and conforms to NSMutableCopying 2) If an extension to the class holding that property redeclares the property as a subclass and qualifies it as "mutableCopy" instead Expected result: Permit this seeming contradiction, declare the property's backing store as the subclass from the extension, not the base class from the header, and implement the setter so it calls -mutableCopy.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!