【发布时间】:2016-08-26 07:09:44
【问题描述】:
我有一个循环依赖问题:当使用新的 RLMLinkingObjects 进行反向关系时,我收到以下错误:
Type argument 'RCon *' does not satisfy the bound ('RLMObject *') of type parameter 'RLMObjectType'
我有两个课程 RCon 和 RSan。 RCon对RSan有多个引用,而RSan又被多个RCon引用,所以是多对多的关系。 以下是类的声明示例。
头等舱:
// RSan.h
#import <Realm/Realm.h>
#import <UIKit/UIKit.h>
@class RCon;
@interface RSan : RLMObject
@property (readonly) RLMLinkingObjects<RCon*>* cons;
@end
RLM_ARRAY_TYPE(RSan)
其他类:
// RCon.h
#import <Realm/Realm.h>
#import <UIKit/UIKit.h>
#import "RSan.h"
@interface RCon : RLMObject
@property RLMArray<RSan*><RSan>* sans;
@end
RLM_ARRAY_TYPE(RCon)
【问题讨论】:
-
除了下面给出的答案之外,您还可以通过仅在关系的一侧使用泛型来解决此 Objective-C 语言限制。
标签: dependencies realm circular-dependency