5

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"

4 Answers4

9

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"

Community
  • 1
  • 1
4

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.

Banshi
  • 1,335
  • 2
  • 13
  • 21
2

You resolve these 'warnings' simply by declaring your strings like so:

statusString = @"";

instead of

statusString = [NSString stringWithString:@""];
Jens Bergvall
  • 1,617
  • 2
  • 24
  • 54
0

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.

rakeshNS
  • 4,227
  • 4
  • 28
  • 42