当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - Realm 0.102.0 save RLMArray

问题描述:

I've already read alike answers (eg. this) but it did not work for me.

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

On console I print "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. If you stick to using only one API you'll have better luck. For instance, with Realm Swift you would write your model as:

import RealmSwift

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

class TicketDetail: Object {
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: