ios xcode 未知类型名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7897268/
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
xcode unknown type name
提问by Esse
I got code like this:
我得到这样的代码:
Match.h:
匹配.h:
#import <Foundation/Foundation.h>
#import "player.h"
@interface Match : NSObject
{
Player *firstPlayer;
}
@property (nonatomic, retain) Player *firstPlayer;
@end
Player.h:
玩家.h:
#import <Foundation/Foundation.h>
#import "game.h"
@interface Player : NSObject
{
}
- (Player *) init;
//- (NSInteger)numberOfPoints;
//- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil;
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *surname;
@property (nonatomic, assign) NSInteger *player_id;
@property (nonatomic, retain) NSString *notes;
@end
Game.h:
游戏.h:
#import <Foundation/Foundation.h>
#import "match.h"
#import "player.h"
@interface Game : NSObject
{
NSMutableArray *matches;
NSMutableArray *players;
NSString *name;
}
-(Game *) init;
@property (nonatomic, retain) NSMutableArray *matches;
@property (nonatomic, retain) NSMutableArray *players;
@property (nonatomic, retain) NSString *name;
@end
Xcode won't compile my project and show me error unknown type 'Player' in Match.h when I declare *firstPlayer.
当我声明 *firstPlayer 时,Xcode 不会编译我的项目并在 Match.h 中向我显示错误未知类型“播放器”。
I tried cleaning project, rebuilding it but without any result...
我尝试清理项目,重建它但没有任何结果......
回答by ott--
The normal way to solve this cycles is to forward declare classes:
解决这个循环的正常方法是转发声明类:
In Match.h:
在 Match.h 中:
@class Player;
@interface Match ...
Player * firstPlayer;
and do #import "Player.h
only in Match.m, not
in Match.h
并且#import "Player.h
只在 Match.m、not
Match.h 中执行
Same for the other two .h files.
其他两个 .h 文件也是如此。