xcode未知类型名称 [英] xcode unknown type name

查看:122
本文介绍了xcode未知类型名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下:

Match.h:

#import <Foundation/Foundation.h>
#import "player.h"

@interface Match : NSObject
{
    Player *firstPlayer;
}

@property (nonatomic, retain) Player *firstPlayer;

@end

Player.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:

#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将无法编译我的项目并向我显示错误当我宣布* firstPlayer时,Match.h中的未知类型'Player'。

Xcode won't compile my project and show me error unknown type 'Player' in Match.h when I declare *firstPlayer.

我尝试清理项目,重建它但没有任何结果......

I tried cleaning project, rebuilding it but without any result...

推荐答案

解决这个周期的正常方法是转发声明类:

The normal way to solve this cycles is to forward declare classes:

在匹配中。 h:

@class Player;
@interface Match ...
    Player * firstPlayer;

并执行 #importPlayer.h 仅在Match.m中,在Match.h中而不是

and do #import "Player.h only in Match.m, not in Match.h

与其他两个.h文件相同。

Same for the other two .h files.

这篇关于xcode未知类型名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆