程序中意外的“@”(XCode)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8198146/
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
unexpected '@' in program (XCode)
提问by olynoise
All of the sudden Xcode is giving me an error "unexpected '@' in program"at the beginning of my object @interface
.
突然间,Xcode在我的对象的开头给了我一个错误“程序中意外的‘@’”@interface
。
This is happening in a bunch of my objects that were previously working...
这发生在我以前工作的一堆对象中......
Here's an example (with errors in comments)
这是一个示例(注释中有错误)
#import <UIKit/UIKit.h>
#import "ONCOChordDiamond.h"
@interface ONCOChordView : UIView //// unexpected '@' in program
{
NSMutableArray* chordDiamonds;
NSUInteger diamondWidth, diamondHeight;
}
@end /////unexpected '@' in program'
So why is Xcode giving me this error? It seems like a bug.
那么为什么 Xcode 给我这个错误呢?这似乎是一个错误。
回答by Aaron Douglas
I doubt you're still having the issue, but if you are check the header file. I pasted in code from the web in a class and the quotation marks weren't the standard " ". The marks were stylized with an opening quote and a closing quote because it came from a webpage. Retyping the quote marks fixed it.
我怀疑你仍然有问题,但如果你检查头文件。我在课堂上粘贴了网上的代码,引号不是标准的“”。标记采用开头引用和结尾引用进行风格化,因为它来自网页。重新输入引号修复了它。
回答by Skyler Saleh
You are including the header from a file that is not compiled as Objective C.
您正在包含未编译为 Objective C 的文件中的标头。
回答by Duncan Babbage
Check for syntax errors in the ONCOChordDiamond.h file. They may be highlighted for you if you run Product > Analyze in Xcode.
检查 ONCOChordDiamond.h 文件中的语法错误。如果您在 Xcode 中运行产品 > 分析,它们可能会为您突出显示。
Importing a file with syntax errors could lead to the compiler not being able to parse the current file correctly, even if the current file's syntax is correct.
导入有语法错误的文件可能会导致编译器无法正确解析当前文件,即使当前文件的语法是正确的。
回答by Slowburner
When encountering this problem with NSString literals, Check that you have used quotation marks, as required.
当 NSString 文字遇到此问题时,请根据需要检查您是否使用了引号。
(eg. @"myString")
If you find your NSStrings are not correctly syntax coloured, you might check for the following offending characters.
如果你发现你的 NSStrings 的语法颜色不正确,你可以检查以下有问题的字符。
" (QUOTATION MARK)
″ (DOUBLE PRIME)
“ (LEFT DOUBLE QUOTATION MARK)
” (RIGHT DOUBLE QUOTATION MARK)
回答by mbm29414
For what it's worth, I had this issue and the offending line that was identified was nowhere near any string literals.
就其价值而言,我遇到了这个问题,并且发现的违规行与任何字符串文字相去甚远。
I didnotice that some of the following lines were colored oddly (again, no string literals to blame), so I tested out putting a bogus string literal in the code just before the offending line.
我确实注意到以下一些行的颜色很奇怪(再次,没有字符串文字可以归咎于),所以我测试了在代码中就在违规行之前放置一个伪造的字符串文字。
NSString *whatever = @"";
Apparently, it convinced the compiler that the line wasn'tscrewed up, so it then compiled just fine without complaining. After that build, I was able to delete the bogus string variable and move on with my life.
显然,它让编译器相信这条线没有搞砸,所以它编译得很好,没有抱怨。在那次构建之后,我能够删除虚假的字符串变量并继续我的生活。
回答by nishant
I had a similar problem and it was because the last quote was getting escaped out. I was using a multiline string with a terminating "\" to eat up the end of line character.
我有一个类似的问题,这是因为最后一个引用被转义了。我正在使用带有终止符“\”的多行字符串来吃掉行尾字符。
[ string appendFormat:@"\n\
vec4 position;\n\
vec4 inputTextureCoordinate;\n\" ];
After I removed the mistaken "\" that ate up the last quote it worked.
在我删除了错误的“\”之后,它耗尽了它工作的最后一个引号。