I am using Xcode9 and I tried to analyse the project.Then I got the following issue like
Property of mutable type 'NSMutableDictionary' has 'copy' attribute; an immutable object will be stored instead
Please go through the image shows the analyze issue
How to resolve this issue?
In Objective-C there is a copy method defined in NSCopying
and other is mutableCopy
, defined in NSMutableCopying
. NSDictionary(superclass of NSMutableDictionary) conforms to both these protocols.
But in property accessors, only copy is available which uses copy method on NSMutableDictionary
to create an immutable object, hence the warning when you run the static analyzer, because you are now trying to store an NSDictionary
object into an NSMutableDictionary
reference.
If you call any NSMutableDictionary
method on this reference, I reckon the app should crash.
To solve this issue, you can either use strong that would hold the reference for you. But, if you really need a copy(for whatever reasons), you can write your own setter, something like this:
@property (nonatomic) NSMutableDictionary *parameters;
- (void)setParameters:(NSMutableDictionary *)parameters {
_parameters = [parameters mutableCopy];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With