xcode 格式字符串不是文字字符串(可能不安全)警告

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12986317/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:52:48  来源:igfitidea点击:

Format String is not a literal string (potentially insecure) warning

objective-ciosxcode

提问by Gregory Ortiz

Possible Duplicate:
Warning: “format not a string literal and no format arguments”

可能重复:
警告:“格式不是字符串文字,也没有格式参数”

I have the following line of code that is in my app that a Developer worked on. I am learning the basics of Objective C and as I was updating the App to be iPhone 5 compatible, I see the following warning (I did not change his code) Format String is not a literal string (potentially insecure). The code is as follows;

我的应用程序中有以下代码行,开发人员正在处理它。我正在学习 Objective C 的基础知识,当我将应用程序更新为与 iPhone 5 兼容时,我看到以下警告(我没有更改他的代码)格式字符串不是文字字符串(可能不安全)。代码如下;

self.progressHud.labelText = [NSString stringWithFormat:message];   

I don't know exactly what this means and don't want to upload anything that can either be a security issue or get rejected by Apple. Any and all help is appreciated from you all.

我不知道这究竟意味着什么,也不想上传任何可能是安全问题或被 Apple 拒绝的内容。感谢大家的任何帮助。

回答by

Use the following Lines:

使用以下几行:

self.progressHud.labelText = [NSString stringWithFormat:@"%@", message]; 

In objective C, this line get the values from any format such as int,float etc to display the Label. because UILabel and IBOutlet Elements only display the NSString values.

在目标 C 中,这一行从任何格式(如 int、float 等)中获取值以显示标签。因为 UILabel 和 IBOutlet 元素只显示 NSString 值。

However, if you don't need to create a string with multiple variables, it would be more efficient to simply use:

但是,如果您不需要创建具有多个变量的字符串,那么简单地使用会更有效:

self.progressHud.labelText = message;