Xcode Warning: using 'stringWithString': with a literal is redundant

I received the following warning

Using 'stringWithString': with a literal is redundant

using the usingWithString method

 [NSString stringWithString:@"Content-Type: content/unknown\r\n\r\n"] 
+4
source share
2 answers

I solved the problem by replacing [NSString stringWithString:@"Content-Type: content/unknown\r\n\r\n"] with @"Content-Type: content/unknown\r\n\r\n"

+9
source

Warning because you are better off using @ "" to initialize the string. For instance:

  NSString *s1 = @"s1"; NSString *s3 = [[NSString alloc] initWithString:@"s1"]; 

we can print their address:

 2017-02-08 11:38:46.997201 Test[7484:2245410] s1:0x10009c088 s1 2017-02-08 11:38:46.997290 Test[7484:2245410] s3:0x10009c088 s1 

we may find that they indicate the same address. So, the apple recommends using "@" "instead of" initWithString ".

0
source

All Articles