我正在尝试使用Restkit进行映射并创建了2个类,如下所示。我收到了以下错误:
我的问题是有一种方法可以通过重用类来实现下面的类声明。
Campaign.h
#import "Card.h"
@interface Campaign : NSObject
@property (nonatomic, strong) NSNumber* campaignId;
@property (nonatomic, strong) NSString* title;
@property (nonatomic, strong) Card* card;
@end
Card.h
#import "Campaign.h"
@interface Card : NSObject
@property (nonatomic, strong) NSNumber* cardId;
@property (nonatomic, strong) NSString* name;
@property (nonatomic, strong) Campaign* campaign;
@end
答案 0 :(得分:2)
通常,在标头中,您使用前向类声明,以避免导入冲突。因此,在Campaign.h
中,在您的界面之前,您已经拥有@class Card
,而在Card.h
中,您拥有@class Campaign
。这只是告诉编译器这些类是否存在&在其他地方定义;这通常只需要在标题中知道。
答案 1 :(得分:1)
以防有人将来需要它。在这里我的解决方案:
<强> Campaign.h 强>
@class Card;
@interface Campaign : NSManagedObject
@property (nonatomic, strong) NSNumber* campaignId;
@property (nonatomic, strong) NSString* title;
@property (nonatomic, strong) Card* card;
@end
<强> Campaign.m 强>
#import "Card.h"
@implementation Campaign
...
@end
<强> Card.h 强>
@class Campaign;
@interface Card : NSManagedObject
@property (nonatomic, strong) NSNumber* cardId;
@property (nonatomic, strong) NSString* name;
@property (nonatomic, strong) Campaign* campaign;
@end
<强> Card.m 强>
#import "Campaign.h"
@implementation Card
...
@end