xcode 我如何处理可可中的警告未知转义序列 '\040'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3704323/
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-14 19:44:16  来源:igfitidea点击:

How do I deal with the warning Unknown escape sequence '\040' in cocoa

cocoaxcodewarnings

提问by Ian Turner

I have the following Warning popping up in a few of the Applescripts I'm running in a Cocoa application:

我在 Cocoa 应用程序中运行的一些 Applescripts 中弹出以下警告:

http://emberapp.com/splash6/images/unknown-escape-sequence-error/sizes/m.png

http://emberapp.com/splash6/images/unknown-escape-sequence-error/sizes/m.png

I have tried everything I can think of to remove the error such as totally rewriting it, copying and pasting from another similar script that doesn't have the warning etc. but I can't get rid of it. Can anyone tell me where I might be going wrong.

我已经尝试了所有我能想到的方法来消除错误,例如完全重写它,从另一个没有警告的类似脚本中复制和粘贴等等,但我无法摆脱它。谁能告诉我我可能哪里出错了。

The raw code I'm using is:

我使用的原始代码是:

NSString *theCellRefScript = [NSString stringWithFormat:@"tell application \"Numbers\"\n\
                                                tell document 1 \n\
                                                tell sheet \"%@\" \n\
                                                tell table \"%@\" \n\
                                                set value of cell \"%@\" to \%@\ \n\
                                                end tell \n\
                                                end tell \n\
                                                end tell \n\
                                                end tell ", theSheet, theTable, theCell, [theDistributionValues objectAtIndex:k]];

回答by Jeff

Don't open yourself up to this sort of problem in the first place.

不要一开始就对这类问题敞开心扉。

Objective-C, like all modern C compilers, automatically concatenates string literals if they are seperated by whitespace. Rather than your multi-line horror with its trailing slashes, use:

与所有现代 C 编译器一样,Objective-C 会自动连接由空格分隔的字符串文字。而不是带有尾部斜杠的多行恐怖,使用:

 NSString *theCellRefScript = [NSString stringWithFormat:@"tell application \"Numbers\"\n"
                                                "tell document 1\n"
                                                "tell sheet \"%@\ \n"
                                                "tell table \"%@\ \n"
                                                "set value of cell \"%@\" to \%@ \n"
                                                "end tell\n"
                                                "end tell\n"
                                                "end tell\n"
                                                "end tell", theSheet, theTable, theCell, [theDistributionValues objectAtIndex:k]];

回答by Graham Perks

You have a trailing space on the end of a line, after the final backslash. It thinks you're trying to escape a space, not join lines.

在最后一个反斜杠之后,在一行的末尾有一个尾随空格。它认为你试图逃离一个空间,而不是加入行。

edit: I'll even tell you how I knew, so you know for next time. From the error text, '040' is an octal number. Convert to decimal, 4 * 8 = 32, and ASCII 32 = space. A space is not a valid escape character. Some editors have a 'show whitespace' mode which'll show you tabs and spaces to help weed out issues like this.

编辑:我什至会告诉你我是怎么知道的,所以你下次知道。从错误文本来看,'040' 是一个八进制数。转换为十进制,4 * 8 = 32,ASCII 32 = 空格。空格不是有效的转义字符。一些编辑器具有“显示空白”模式,该模式将向您显示选项卡和空格以帮助消除此类问题。

回答by Ian Turner

Found the problem, there was a rogue space on the line starting set value of cell. The working version is:

发现问题了,cell的起始设置值那一行有一个rogue space。工作版本是:

set value of cell \"%@\" to \%@\n\

回答by Sam Azer

This was driving me nuts because I really just couldn't see it. In my case it turned out to be rather simple: In my help text I had written that a certain option would escape all spaces - and I gave an example,

这让我发疯,因为我真的看不到它。就我而言,结果相当简单:在我的帮助文本中,我写了某个选项会转义所有空格 - 我举了一个例子,

"\ "

Of course this became something like:

当然,这变成了这样:

"\"\ \""

It's not visually obvious at all... but the backslash in the middle needs to be escaped, too:

它在视觉上根本不明显……但是中间的反斜杠也需要转义:

"\"\ \""

HTH

HTH