简体   繁体   English

领域0.102.0保存RLMArray

[英]Realm 0.102.0 save RLMArray

I've already read alike answers (eg. this ) but it did not work for me. 我已经读过类似的答案(例如this ),但是它对我不起作用。

I have: 我有:

import Realm
import RealmSwift

class Ticket: Object {

    dynamic var ticketDetails = RLMArray(objectClassName: TicketDetail.className())

}

class TicketDetail: Object {
}

When I create a new ticket, app crash at this line: 当我创建新票证时,应用程序在以下行崩溃:

// Helper for getting the list object for a property
internal func listForProperty(prop: RLMProperty) -> RLMListBase {
    return object_getIvar(self, prop.swiftIvar) as! RLMListBase
}

with: 有:

fatal error: unexpectedly found nil while unwrapping an Optional value 致命错误:解开Optional值时意外发现nil

On console I print "prop": 在控制台上,我打印“ prop”:

po prop
ticketDetails {
    type = array;
    objectClassName = TicketDetail;
    linkOriginPropertyName = (null);
    indexed = NO;
    isPrimary = NO;
    optional = NO;
}

If I print "self": 如果我打印“自我”:

Ticket {
   ticketDetails = RLMArray <0x7fee6c1d7880> (
    [0] TicketDetail {
    }
   );     
} 

So what? 所以呢? I can't figure out why crash! 我不知道为什么会崩溃! Could anyone help me? 有人可以帮我吗?

You're mixing types from the Realm Swift API ( Object ) and Realm Objective-C API ( RLMArray ) in a way that's not supported. 您正在以不支持的方式混合Realm Swift API( Object )和Realm Objective-C API( RLMArray )中的类型。 If you stick to using only one API you'll have better luck. 如果您只使用一种API,那么运气会更好。 For instance, with Realm Swift you would write your model as: 例如,使用Realm Swift,您可以将模型编写为:

import RealmSwift

class Ticket: Object {
    let ticketDetails = List<TicketDetail>()
}

class TicketDetail: Object {
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM