【问题标题】:Why does the warnings only appear when my iPhone is NOT connected to my Mac?为什么只有当我的 iPhone 未连接到我的 Mac 时才会出现警告?
【发布时间】:2015-06-30 12:56:54
【问题描述】:

不是重复,但警告消息是相同的。我读了这篇文章,但没有帮助。

performSelector may cause a leak because its selector is unknown

我没有使用 performSelector,但我收到的警告与使用时相同。

Xcode 6.3 中的警告信息是

 PerformSelector may cause a leak because its selector is unknown

代码是

NSString *string=[NSString stringWithFormat:@"%tu", data.length];
NSLog(@" Expected :%lli",[response expectedContentLength]);

data.length 应该返回一个 NSUInteger

expectedContentLength 是 long long

当我将 %tu 更改为 %zu 时,我收到一条新的警告消息

 Values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead

【问题讨论】:

  • 因为在您的 Build Settings 中,您将 Build Active Architecture 设置为 YES。该警告与 32 位和 64 位架构有关,并且您使用了无效的格式参数。

标签: ios iphone xcode compiler-warnings


【解决方案1】:

警告是关于 NSUInteger 的大小取决于 CPU 架构的变化,并且可能仅在发布版本期间发生(我理解为“未连接到 Mac”),因为发布版本包含所有有效的 CPU 架构( 32 位和 64 位),而调试版本仅包含用于调试的设备的体系结构。 (如果您没有更改默认设置的构建设置,这是正确的)。

NSUInteger 改变大小时,假设它是unsigned long 并使用强制转换:

NSString *string=[NSString stringWithFormat:@"%lu", (unsigned long)data.length];

【讨论】:

  • 我所有的设置都是默认的。
  • 我应该为 expectedContentLength 转换什么?
  • 它的数据类型是什么?
  • long long 是数据类型
  • 你根本不需要投射它。
猜你喜欢
  • 2020-08-17
  • 1970-01-01
  • 1970-01-01
  • 2017-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多