Objective-C中非托管RLMObjects中的RLMArray属性 [英] RLMArray properties in unmanaged RLMObjects in Objective-C

查看:177
本文介绍了Objective-C中非托管RLMObjects中的RLMArray属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在任何地方都找不到很好的示例代码....但是我发现的信息矛盾而又令人困惑...

I cannot find a good example code of this anywhere....but the information I find is contradictory and confusing...

@interface DAORealmMetadata : RLMObject
@property (nonatomic, copy) NSString*     id;
@end
RLM_ARRAY_TYPE(DAORealmMetadata)

@interface DAORealmBase : RLMObject
@property (nonatomic, copy) NSString*     id;
@property (nonatomic, copy)  RLMArray<DAORealmMetadata*><DAORealmMetadata>*      metadata;
@end
RLM_ARRAY_TYPE(DAORealmBase)

问题: 我应该在DAORealmBase实现中添加@dynamic metadata吗?

Question: Am I supposed to add @dynamic metadata in the DAORealmBase implementation...or not?

无论有没有尝试,最终结果都一样……崩溃.

I've tried it with and without and have the same end result...a crash.

我使用以下代码创建非托管对象:

I create the unmanaged object with this code:

DAORealmBase* baseObj = [[DAORealmBase alloc] init];

DAORealmMetadata* metadataObj = [[DAORealmMetadata alloc] init];

[baseObj.metadata addObject:metadataObj];

问题: 为什么最后一行会导致崩溃/异常?

我只能以为自己做错了什么,但找不到我做过的任何事情.

I can only assume that I"m doing something wrong, but I cannot find any specifics as to what I did.

谢谢!

推荐答案

好,我一直跟踪问题,并通过反复试验,确定问题是RLMArray属性的属性.

Well, I tracked the problem down, and through some trial and error, determined that the problem was the property attributes on the RLMArray properties.

更改

@property (nonatomic, copy) RLMArray<DAORealmMetadata*><DAORealmMetadata>* metadata;

@property RLMArray<DAORealmMetadata*><DAORealmMetadata>* metadata;

似乎已解决了问题.我特别相信'copy'属性.

seems to have resolved the problem. I believe specifically the 'copy' attribute.

现在,我知道Realm文档说这些属性被忽略了,不需要,但是我使用的皮棉检查器希望在那里...而且由于它们被忽略"了,所以有什么害处?

Now, I know that the Realm docs say that the attributes are ignored and not needed, but the lint checker I'm using wants them there...and since they are "ignored", what's the harm?

好吧,在普通的Realm属性中,它们将被忽略,但是在RLMArray属性中,它们将不会被忽略,并随之而来.

Well, they are ignored on normal Realm properties, but on the RLMArray properties they aren't ignored, and problems ensue.

希望这将对以后的其他人有所帮助,并为他们节省一些时间.

Hopefully this will help someone else in the future and save them some time.

这篇关于Objective-C中非托管RLMObjects中的RLMArray属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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