string值总是在目标C中显示为零

我已经升级到Xcode 5.0。 而当我在debugging模式下运行一个应用程序,并尝试在控制台中打印NSString值,它给了我下面的错误。 有任何想法吗?

 error: warning: couldn't get cmd pointer (substituting NULL): Couldn't load '_cmd' because its value couldn't be evaluated Couldn't materialize struct: the variable 'stringValue' has no location, it may have been optimized out Errored out in Execute, couldn't PrepareToExecuteJITExpression 

这里是代码:

 NSString *stringValue = [[self.responseArray objectAtIndex:i] valueForKey:@"merchant_name"]; 

原因是在错误消息中说明: 它可能已被优化出来 ..这意味着你正在编译和运行你的代码在一个优化的方式。

您必须将您的编译器优化级别从Fastest,Smallest更改为none

  • 去你的目标构build设置
  • search优化级别
  • 将其更改为none(无论您处于哪种模式,即debugging,分发或发布)

为您的项目设置做同样的事情

确保您处于debugging模式。 去编辑计划 > build立configuration >debugging

您可能正试图在“发行计划”中进行debugging。 转到“产品/计划/编辑计划”,然后select左侧面板中的“运行”。 然后将构buildconfiguration更改为“debugging”。

一个替代的答案:通过删除优化,而不是固定“它可能已被优化出来”,你可以通过使用variables停止优化。

所以,在你的问题中,如果你用stringValue做些什么:

 NSString *stringValue = [[self.responseArray objectAtIndex:i] valueForKey:@"merchant_name"]; NSLog(@"%@", stringValue); 

stringValue将不再被优化,因为你正在使用它。

如果要查看项目中所有已优化variables的实例,请使用产品 – > 分析来分析项目。 如果您打开了编译器优化,任何“死亡存储”警告(在其中存储值,从不读取)将在编译时被优化。