XCode 4.2 .h 模块中缺少 @end + 预期标识符“{”错误

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

missing @end + expected identifier "{" errors in XCode 4.2 .h module

objective-ciosxcode

提问by Matias Masso

I can't get rid of two errors on my class module, even when I have simplified the code to the minimum expression:

我无法摆脱类模块上的两个错误,即使我已将代码简化为最小表达式:

#import <Foundation/Foundation.h>

@interface MyClass : NSObject

@end

Both errors are reported on the @interface line, and they are: - missing @end - expected identifier or '{'

这两个错误都报告在@interface 行上,它们是: - 缺少 @end - 预期标识符或“{”

回答by JasonD

Check the header files that are #imported on the same page, and verify that the headers have matching @interface/@end statements.

检查在同一页面上#imported 的头文件,并验证头文件是否具有匹配的@interface/@end 语句。

I had the same problem, and XCode reported that my .m file's @implementation had a missing @end statement, even when I pared it down to just:

我遇到了同样的问题,XCode 报告说我的 .m 文件的 @implementation 缺少 @end 语句,即使我将其缩减为:

#import "MasterViewController.h"
#import "MyBadHeaderFile.h"
@implementation MasterViewController
@end

In reality the bug was a missing @end from a #imported MyBadHeaderFile.h file.

实际上,该错误是#imported MyBadHeaderFile.h 文件中缺少@end。

回答by wharding11

I had a similar problem found adding a }in my code got rid of the errors for me.

我发现}在我的代码中添加一个类似的问题为我消除了错误。

Before I added the }I was getting the following errors:

在我添加之前,}我收到以下错误:

  1. unexpected @in program (parse issue)
  2. Expected }(parse issue)
  3. @endis missing in implementation context (semantic issue)
  1. @程序中意外(解析问题)
  2. 预期}(解析问题)
  3. @end在实现上下文中缺失(语义问题)

回答by thanhbinh84

rokjarc's comment should be a correct answer:

rokjarc 的评论应该是正确的答案:

1) compiler can point you to completely wrong file. go trough all .h and .m files in your project and check for matching '@interface'/'@end', '@implementation'/'@end' and so on.

1) 编译器可以将您指向完全错误的文件。遍历项目中的所有 .h 和 .m 文件并检查匹配的“@interface”/“@end”、“@implementation”/“@end”等。

2) it happens also if you by mistake import .m file instead of .h

2) 如果您错误地导入 .m 文件而不是 .h 也会发生这种情况

回答by Pruthvid

It doesnt matter in which file the error is appearing. Make sure to check for all the files you have recently modified. I appeared to have copied a file from test project to my actual project and forgot @end in one of the files. It gave me error on totally unrelated .h file.

错误出现在哪个文件中并不重要。确保检查您最近修改过的所有文件。我似乎已将测试项目中的文件复制到我的实际项目中,但在其中一个文件中忘记了 @end。它给了我完全不相关的 .h 文件错误。

回答by Mokhles

Try to remove the implementation file of this class from "Compile sources in project settings"

尝试从“在项目设置中编译源代码”中删除此类的实现文件

回答by Jonathan García

I had the same error ,and it was because i had

我有同样的错误,那是因为我有

@interface MyViewController ()

declared two times in the MyViewController.m

在 MyViewController.m 中声明了两次

回答by aahsanali

@interface MyClass : NSObject{

}

@end

回答by Keab42

I experienced a similar issue, the code was fine but it was throwing this error.

我遇到了类似的问题,代码很好,但它抛出了这个错误。

I eventually resolved it by cleaning the project, have you tried that?

我最终通过清理项目解决了它,您尝试过吗?

回答by james_womack

PEBKAC + Lack of Specificity in the Static Analyzer Strings

PEBKAC + 静态分析器字符串缺乏特异性

The existing answers are certainlyuseful. I just want to add a common PEBKAC that causes this; as well as highlight that CLANG should be clearer here. Someone with domain knowledge should file a patch to make the error message clearer. The \n@end\npart of the message is ridiculous no matter what.

现有的答案当然有用。我只想添加一个导致这种情况的常见 PEBKAC;并强调 CLANG 在这里应该更清楚。具有领域知识的人应该提交补丁以使错误消息更清晰。\n@end\n无论如何,消息的部分都是荒谬的。

(Showing line breaks as \nin a message designed to help users of a GUI? ReallyCLANG?)

(在旨在帮助 GUI 用户的消息中将换行符显示为\n真的CLANG?)

The Cause

原因

When you have just created a new Class, the @interface& @implementationfiles look extremely similar, and Xcode will automatically place your cursor in the implementation.

当你刚刚创建了一个新的类时,@interface&@implementation文件看起来非常相似,Xcode 会自动将你的光标放在实现中。

If you thoughtlessly begin typing out your interface (your method signature declarations) in the implementation file, you'll end up with this warning because the analyzer sees methods without opening and closing braces.

如果您不假思索地开始在实现文件中输入您的接口(您的方法签名声明),您最终会收到此警告,因为分析器看到的方法没有左括号和右括号。

A visual example, shown forthwith

一个直观的例子,立即显示

Missing @end is a case of PEBKAC

缺少@end 是 PEBKAC 的一个案例