Using 'stringWithString:' with a literal is redundant [duplicate]

廉价感情. 提交于 2019-11-29 14:44:24

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!