XCode:预期标识符或“(”

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

XCode: Expected identifier or '('

iosobjective-cxcode

提问by RikSaunderson

We created an iOS app quite a while ago which works perfectly on the Mac on which it was developed, but which throws up errors when we try to compile it on a different Mac.

不久前我们创建了一个 iOS 应用程序,它在开发它的 Mac 上运行良好,但是当我们尝试在不同的 Mac 上编译它时会引发错误。

In order to transfer it to the second Mac, we simply copied the entire source directory onto a USB stick. If this is the cause of my issues, then could somebody let me know a better way to transfer projects.

为了将其传输到第二台 Mac,我们只需将整个源目录复制到 U 盘上。如果这是我问题的原因,那么有人可以让我知道转移项目的更好方法。

The project has a number of dependencies pulled in through CocoaPods. The Pods project/target builds correctly on both Macs.

该项目通过 CocoaPods 引入了许多依赖项。Pods 项目/目标在两台 Mac 上都能正确构建。

For legacy compatibility reasons both Macs are runnign XCode 5.0.2 and compiling for iOS 6.1.

出于遗留兼容性原因,两台 Mac 都运行 XCode 5.0.2 并为 iOS 6.1 编译。

When trying to build the main project, we get several errors of the type:

在尝试构建主项目时,我们会收到以下类型的几个错误:

? Expected identifier or '('

? 预期标识符或 '('

? Unexpected ‘@' in program

? 程序中出现意外的“@”

? Missing context for method declaration

? 缺少方法声明的上下文

? Expected method body

? 预期的方法体

This is an example of the compilation errors on one of my header files (note once again that the code is exactly the same as that which is compiles correctly on the other Mac):

这是我的一个头文件上的编译错误示例(再次注意,代码与在另一台 Mac 上正确编译的代码完全相同):

#import <UIKit/UIKit.h>
@interface DiagnosticViewController : UIViewController <UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UITextView *diagnosticReadout;
@property (weak, nonatomic) IBOutlet UITextField *connectionNameTextBox;  <- Unexpected ‘@' in  program
-(void) messageReceived:(NSString*)webPublisherMessage;     <- Missing context for method declaration
@end         <-Expected method body

Does anyone have any ideas about what's going on? I can only assume that there's something wrong with the build settings or include paths or something, but I've checked through all of them and they all appear to be identical on both Macs.

有没有人对正在发生的事情有任何想法?我只能假设构建设置或包含路径有问题,但我已经检查了所有这些,它们在两台 Mac 上似乎都相同。

回答by StinkyCat

Check if you don't have any white space character before that line. Just set the cursor on the beginning of the @property that is giving you trouble and try pressing the backspace once or twice. See if the error goes away. This is what worked for me

检查该行之前是否没有任何空格字符。只需将光标设置在给您带来麻烦的@property 的开头,然后尝试按一次或两次退格键。查看错误是否消失。这对我有用

回答by CarlesCF

I had an issue like that some time ago.

前段时间我也遇到过这样的问题。

You should clean the project. If still does not work check for any errors related to XCode not able to create/modify/delete files, since you copied the content from the USB you may have files permissions issues. You could set all the files permissions under the project directory to 777 to the user it is running.

你应该清理项目。如果仍然不起作用,请检查与 XCode 相关的任何错误,无法创建/修改/删除文件,因为您从 USB 复制了内容,您可能有文件权限问题。您可以将项目目录下的所有文件权限设置为 777 给它正在运行的用户。

The reason, in my opinion, is that the files being compiled differ from the source code you are looking to.

在我看来,原因是正在编译的文件与您要查找的源代码不同。