iphone - 如何在 iOS 上使用 NSLog 打印字符串常量

标签 iphone ios string constants nslog

我有一个这样定义的字符串常量:

#define kMyString @"This is my string text!";

在代码的某处,我想像这样用 NSLog 打印出这段代码:

NSLog(@"This is it: %@",kMyString);

但是得到一个构建错误:Expected expression

我已经看过 Apple 的 Format Specifiers但想不通。

有人可以向我解释一下如何做到这一点吗?

谢谢!

最佳答案

您应该从 kMyString 的定义中删除 ;:

#define kMyString @"This is my string text!"

你这样做的方式相当于:

NSLog(@"This is it: %@", @"This is my string text!";);

关于iphone - 如何在 iOS 上使用 NSLog 打印字符串常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9617301/

相关文章:

iphone - Three20 中的 TTSpeechBubbleShape 仅绘制 "speech"三角形顶部和底部

ios - 从 XCode 4.x 提交 ios6 应用程序

swift - str = str + "abc"比 str = "abc"+ str 慢?

python - 最有效的方法——测试 2 个字符串的 Python 字谜

regex - yytext 包含不匹配的字符

ios - 从一个 View Controller 选择的多个数组元素到另一个 View Controller

iphone - 录制音频时如何将音频录制设置更改为16Khz和16位?

iphone - 无法获取 FileCreationDate?

ios - 当用户在 Swift 中选择 UISegmentedControl 时,如何更改它的样式?

ios - 捆绑标识符不能从以前的版本更改