Realm crash on iOS 10 with 'String'

Viewed 232

I have recently released a new version of our app and during beta testing, it's crashing on all iOS 10 devices but not other versions. Since we have Crashlytics, we found a strange crash message in the backend that we can confirm is the reason all iOS 10 crashing since it's 100% iOS 10 and there's like 40 of them.

It reads as follows:

Fatal Exception: RLMException Property Article.id is declared as String, 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 here's the object:

class Article: Object {
    
    @objc dynamic var id: String = UUID().uuidString
    // others...

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

As you can see, this is perfectly nomral and runs fine on other iOS. In Realm's doc, it LITERALLY SAYS to use String with @objc dynamic and there's no way it's unsupported. I suspect there's nothing special about Article.id, and since Article starts with A, it happens to be the first String property of all realm Objects. Maybe somehow all Strings stopped working on iOS 10?

Can anyone offer some advice or insights?(Please don't say things like drop iOS 10 support. For now, we need it.)

2 Answers

We ran into the same issue a couple of times, trying to drag Realm fully into Swift. This is not really the answer but more of a workaround we've had success with when needing backward compatibility.

It's an ObjC object, not Swift.

There's something going on with the bridging, perhaps conforming to NSCopy'ing or something along those line, so just change it to read

@objc dynamic var id = NSUUID().uuidString

See the Getting Started Guide in the Models section which calls for using NSUUID

NSUUID: An object representing a universally unique value that bridges to UUID; use NSUUID when you need reference semantics or other Foundation-specific behavior.

Turns out it was a Realm's bug. We happen to have another app that runs just fine on iOS 10, and after some inspection we realized that it was using Realm 4.3.2, instead of 4.4.1. After we downgraded Realm to 4.3.2, this problem disappeared.

Related