Luca Davanzo
Luca Davanzo

Reputation: 21520

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?

Upvotes: 1

Views: 115

Answers (1)

bdash
bdash

Reputation: 18308

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 {
}

Upvotes: 2

Related Questions