Error on a list of 0 elements

Property ModelM.plazoS is declared as Array, which is not a supported managed Object property type. If it is not supposed to be a managed property, either add it to ignoredProperties() or do not declare it as @objc dynamic. See https://realm.io/docs/swift/latest/api/Classes/Object.html for more information.

And ModelM is declared as

import Foundation
import RealmSwift

public class ModelMatriz:Object {
    dynamic private var min = RealmOptional<Float>()
    dynamic private var max = RealmOptional<Float>()
    @objc dynamic private var plazoS:[String] = []
}

I got that error from this piece of code (last line is the one from the quote above)

return getNonIgnoredMirrorChildren(for: object).compactMap { prop in
            guard let label = prop.label else { return nil }
            var rawValue = prop.value
            if let value = rawValue as? RealmEnum {
                rawValue = type(of: value)._rlmToRawValue(value)
            }

            guard let value = rawValue as? _ManagedPropertyType else {
                if class_getProperty(cls, label) != nil {
                    throwRealmException("Property \(cls).\(label) is dec..."

But plazoS should be managed by Realm, and there are other members that are also [String]and they seem to work correctly.

so I used lldb and got this:

(lldb) po rawValue 
0 elements

(lldb) print rawValue 
([String]) $R12 = 0 values {}

You can’t store an array of strings in Realm as a managed object. It’s not supported. There are a number of solutions

Option 1: Store the String in a list property

public class ModelMatriz:Object {
    dynamic private var min = RealmOptional<Float>()
    dynamic private var max = RealmOptional<Float>()
    let plazoS = List<String>()
}

however - and this may be very important

Note that querying List’s containing primitive values is currently not supported.

Option 2: A better solution is to create a managed realm object that contains a string proprety

class PlazosClass: Object {
   @objc dynamic var someString = ""
}

public class ModelMatriz:Object {
    dynamic private var min = RealmOptional<Float>()
    dynamic private var max = RealmOptional<Float>()
    let plazoS = List< PlazosClass >()
}

Oh, if you want min and max to be managed you’ll need to add @objc to those vars

@objc dynamic private var min = RealmOptional<Float>()
@objc dynamic private var max = RealmOptional<Float>()
2 Likes

Yes, it was this, I put everywhere List, but the problem with this is that it was breaking with an exception and no print on debugger terminal (even thought I think exceptions have strings that describe them).

You should add a breakpoint in your code and step through it line by line, examining the code flow and your vars along the way. When something doesn’t perform as expected - for example a var being nil when it should have had a string, you can then troubleshoot from there.

Oh yeah, for sure I know how to debug even cryptic things :slight_smile: but as I have said, here is what I needed to do to track down where… https://github.com/realm/realm-cocoa/issues/6096#issuecomment-597407518 but as I have said the console didnt print the real source of the error like “put List instead of array” or something more helpful that doesnt require “debug skillz”

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.