This question already has an answer here:
i used this code in reachability class that is in ios6
switch (status) {
case kNotReachable:
statusString = [NSString stringWithString: @"Not Reachable"];
break;
case kReachableViaWWAN:
statusString = [NSString stringWithString: @"Reachable via WWAN"];
break;
case kReachableViaWiFi:
statusString = [NSString stringWithString: @"Reachable via WiFi"];
break;
}
but the following error is occurred "Using 'stringWithString:' with a literal is redundant"
The warning is saying that you could instead easily do like this:
statusString = @"Not Reachable";
The explanation is provided in the post Obj-C: [NSString stringWithString:@"string"] vs. @"string"
Instead of using
statusString = [NSString stringWithString: @"Not Reachable"];
please write your code like below:
statusString = @"Content-Type: Not Reachable/unknown\r\n\r\n";
warning will be removed.
You resolve these 'warnings' simply by declaring your strings like so:
statusString = @"";
instead of
statusString = [NSString stringWithString:@""];
I think this is a type of compiler optimization. Actually you need to assign a string to variable. You can do it directly as myString = @""
no need to call a method and it will use additional processing time.
来源:https://stackoverflow.com/questions/13373826/using-stringwithstring-with-a-literal-is-redundant