Arik Segal
Arik Segal

Reputation: 3031

Adding a list of strings to a Realm managed object causes the app to crash on launch

In the following code, adding the "let members =" declaration causes the app to immediately crash on launch.

The crash is an EXC_BAD_ACCESS and the stack trace points to Object.swift -> getNonIgnoredMirrorChildren

import Foundation
import RealmSwift

class GroupSyncModel : Object, Codable {
    @objc dynamic var created : String?
    @objc dynamic var name : String?
    @objc dynamic var groupId : String // Primary key
    @objc dynamic var adminUserId : String?
    @objc dynamic var adminUserName : String?
    @objc dynamic var joinedAt : String?

    let members = List<String>()

    override static func primaryKey() -> String? {
        return "groupId"
    }
}

Has anyone else encountered this issue?

Upvotes: 1

Views: 269

Answers (1)

Rob C
Rob C

Reputation: 5073

I've seen this. I know it seems that your members property is the problem but it's actually the groupId property. groupId needs to have a default value.

Change this:

@objc dynamic var groupId : String

To this:

@objc dynamic var groupId : String = "SOME_DEFAULT_STRING_VALUE"

Upvotes: 5

Related Questions