Xcode 4.6.3 中的解析问题 - “预期类型” - 找不到错误

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

Parse Issue in Xcode 4.6.3 - "Expected a type" - Can't find the error

iosobjective-cxcode

提问by Robin des Bois

I have a Problem with Xcode:

我的 Xcode 有问题:

At the moment I am working on an application for iOS SDK 6.1. Somedays ago I was implementing some methods and tried to compile the project. Then something strange happened:

目前我正在为 iOS SDK 6.1 开发一个应用程序。前几天我正在实现一些方法并尝试编译该项目。然后奇怪的事情发生了:

Compilation failed and I got some errors (see picture below) in two files, which aren't related to the methods I worked on.

编译失败,我在两个文件中出现了一些错误(见下图),这与我使用的方法无关。

I searched for errors in my code but couldn't find any.
Then I closed the project and opened it again: They were still here.
Then I closed the project and Xcode and reopened both: They were still here.
Then I created a new project and copied all the code: The issue appeared again.

我在我的代码中搜索错误,但找不到任何错误。
然后我关闭了项目并再次打开它:他们还在。
然后我关闭了项目和 Xcode 并重新打开它们:它们还在。
然后我新建了一个项目,复制了所有的代码:问题又出现了。

Now I am stuck and have no clue what to do. Do I miss something in my code?

现在我被卡住了,不知道该怎么办。我是否遗漏了代码中的某些内容?

Please help me!

请帮我!

---

---

EDIT 1:

编辑 1:

Here are some code snippets, which should show my code after I followed the suggestions of Martin R:

以下是一些代码片段,在我遵循 Martin R 的建议后,它们应该会显示我的代码:

//  PlayingCardDeck.h  
@class PlayingCard;  
@interface PlayingCardDeck : NSObject  
- (void) addCard: (PlayingCard *) card atTop: (BOOL) atTop;  
- (PlayingCard *) drawRandomCard;  
- (BOOL) containsCard: (PlayingCard *) card;  
- (BOOL) isCardUsed: (PlayingCard *) card;  
- (void) drawSpecificCard: (PlayingCard *) card;  
- (void) reset;  
@end  


//  PlayingCardDeck.m  
#import "PlayingCardDeck.h"  
@interface PlayingCardDeck()  


//  PlayingCard.h  
#import <Foundation/Foundation.h>  
#import "RobinsConstants.h"  
#import "PlayingCardDeck.h"  
//@class PlayingCardDeck;  
@interface PlayingCard :  NSObject  
+ (NSArray*) suitStrings;  
+ (NSArray*) rankStrings;  
+ (NSUInteger) maxRank;  
- (id)initCardWithRank: (NSUInteger) r andSuit: (NSString*) s;  
- (NSString*) description;  
- (NSUInteger) pokerEvalRankWithDeck: (PlayingCardDeck *) deck;  
- (NSAttributedString *) attributedContents;  
- (BOOL) isEqual:(PlayingCard*)object;  
@property (strong, nonatomic) NSString *contents;  
@property (nonatomic, getter = isUsed) BOOL used;  
@property (nonatomic, readonly) NSInteger rank;
@property (nonatomic, readonly, strong) NSString * suit;  
@end


//  PlayingCard.m  
#import "PlayingCard.h"  
@interface  PlayingCard()


回答by Martin R

That looks like a typical "import cycle":

这看起来像一个典型的“导入周期”:

 // In PlayingCardDeck.h:
 @import "PlayingCard.h"

 // In PlayingCard.h:
 @import "PlayingCardDeck.h"

Replacing one of the @importstatements by @classshould solve the problem, e.g.

替换其中一个@import语句@class应该可以解决问题,例如

 // In PlayingCardDeck.h:
 @class PlayingCard; // instead of @import "PlayingCard.h"

And in the implementation file you have to import the full interface:

在实现文件中,您必须导入完整的接口:

 // In PlayingCardDeck.m:
 #import "PlayingCardDeck.h"  
 #import "PlayingCard.h"    // <-- add this one

回答by Joride

There is something wrong in PlayingCard.h. This error causes the compiler to not know what a "PlayingCard *" is. Can you show the code from PlayingCard.h?

PlayingCard.h 有问题。此错误导致编译器不知道“PlayingCard *”是什么。你能显示 PlayingCard.h 中的代码吗?

回答by Mario

Make sure the PlayingCard.m is added to your applications target! I would think it isn't (click the .m file and check your apps target in the inspector window on the right side pane)

确保将 PlayingCard.m 添加到您的应用程序目标!我认为它不是(单击 .m 文件并在右侧窗格的检查器窗口中检查您的应用程序目标)