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

发布于 2024-12-12 08:11:58 字数 200 浏览 1 评论 0原文

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

#import <Foundation/Foundation.h>

@interface MyClass : NSObject

@end

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

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 '{'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

淡墨 2024-12-19 08:11:58

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

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

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

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

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

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:

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

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

枕花眠 2024-12-19 08:11:58

我遇到了类似的问题,发现在代码中添加 } 消除了我的错误。

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

  1. 程序中意外的 @ (解析问题)
  2. 预期 } (解析问题)
  3. 实现上下文中缺少@end(语义问题)

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. @end is missing in implementation context (semantic issue)
睫毛溺水了 2024-12-19 08:11:58

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

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

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

rokjarc's comment should be a correct answer:

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.

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

-小熊_ 2024-12-19 08:11:58

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

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.

◇流星雨 2024-12-19 08:11:58

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

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

半岛未凉 2024-12-19 08:11:58
@interface MyClass : NSObject{

}

@end
@interface MyClass : NSObject{

}

@end
·深蓝 2024-12-19 08:11:58

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

我最终通过清理项目解决了这个问题,你尝试过吗?

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?

夏有森光若流苏 2024-12-19 08:11:58

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

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

(在旨在帮助用户的消息中将换行符显示为 \n
图形用户界面? 真的叮叮当当?)

原因

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

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

立即显示一个视觉示例

Missing @end is a case of PEBKAC

PEBKAC + Lack of Specificity in the Static Analyzer Strings

The existing answers are certainly useful. 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\n part of the message is ridiculous no matter what.

(Showing line breaks as \n in a message designed to help users of a
GUI? Really CLANG?)

The Cause

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

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

你另情深 2024-12-19 08:11:58

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

@interface MyViewController ()

在 MyViewController.m 中声明了两次

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

@interface MyViewController ()

declared two times in the MyViewController.m

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文