我有两节课。
GameData.h
#import "TeamData.h"
@property (assign, nonatomic) GameData* teamA;
TeamData.h
@interface TeamData : NSObject
@property (nonatomic, copy) NSString* teamName;
-(void) printTeamData;
一些问题:
在GameData.m中我有这段代码:
TeamData * team = self.teamA; [team printTeamData];
第一行显示此警告:
Incompatible pointer types from TeamData* with an expression of type TeamData*
答案 0 :(得分:1)
在GameData.h中,您的属性指向自己的类,而不是TeamData
@property (assign, nonatomic) GameData* teamA;
assign
适用于原始类型,例如BOOL或NSInteger。
父类应该对子对象持有strong
引用。
所以你的财产会更好
@property (strong, nonatomic) TeamData* teamA;
至于设置teamA属性,您可以在setTeamA:
个实例上调用GameData
:
[myGameData setTeamA:...];