Realm on iPhone Exception on read

Let me re-pose my questions so we understand more of what you’re trying to do. It’s critical to know what platform you’re using and in which way you’re using it

TL;DR

In a nutshell, you’re populating a var users but it’s not the same users you’re trying to access when reading data from it.

More

  1. Are you using ‘classic’ Realm with the SDK version # 5.3.x as shown here (4.x in your case)

or are you using the BETA MongoDB Realm SDK 10.x as shown here

  1. I believe you mentioned your data is stored locally and not sync’ing. Is that correct?

  2. Your message above states this code is not working on a real device and crashes

    let realm = try! Realm()
    var users: Results?
    users = realm.objects(PersonalData.self)
    nameLabel.text = users?[0].name

If that’s correct, it shouldn’t be crashing as long as data exists in the database. There are a few issues with the code though and this code is suspect

if users?.count > 0 {
     nameLabel.text = users?[0].name
}

as if users is an optional as shown in your question

var users: Results<PersonalData>?

, then that code will throw an error in XCode and won’t compile (Value of optional type ‘Int?’ must be unwrapped to a value of type ‘Int’). That tells me you have another var users floating around in your code - possibly a local one within a function which is not the same as a class var. I am a big proponent of addressing class vars with self and not naming vars with the same name.

If this is the code in your object it’s not correct

override class func primaryKey() -> String? {
   return "personalID"
}

Please replace it with

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

I looked at the two errors which centered around not being able to find Realm.framework and RealmSwift.framework in my project

That’s a different issue than what was originally asked (about crashing on a real device with an out of bounds error). Can you clarify how that ties in?