最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【未解决】iOS中初始化NSString出错:Using ‘initWithString’ with a literal is redundant

iOS crifan 2816浏览 0评论

【问题】

在iSO中初始化一个NSString 变量使用如下代码:

self.locationInput.text = [[NSString alloc] initWithString:@"captured change"];

结果出错:

Using ‘initWithString’ with a literal is redundant

Using initWithString with a literal is redundant

 

【解决过程】

1.网上找到的:

OC-3826Inspection for stringWithString

XCode Warning: Using ‘stringWithString’: with a literal is redundant

Xcode升级后的Bug处理

都是使用stringWithString时遇到的此警告,但是我这里的是initWithString

2.尝试改为:

self.locationInput.text = @"captured change";

然后警告是可以消除了。但是还是不知道之前错误的根本原因。

 

【总结】

暂没搞懂Xcode中,对于NSString初始化时,使用:

[[NSString alloc] initWithString:@"captured change"]

而显示警告:

Using ‘initWithString’ with a literal is redundant

的根本原因。

只知道改为:

self.locationInput.text = @"captured change";

是可以消除警告的。

转载请注明:在路上 » 【未解决】iOS中初始化NSString出错:Using ‘initWithString’ with a literal is redundant

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.162 seconds, using 22.12MB memory