Beginning Realm on iOS - Part 3: Storing and | Ray Wenderlich

Try creating new objects and persisting them automatically on disk. Learn how to fetch data back once saved on disk.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4146-beginning-realm-on-ios/lessons/3

Beware: the project’s podfile uses an older Realm version Realm 2.6.0. Which seem to be incompatible with new Realm Browser. As soon as you will run an app with updates to persist data to Realm and have the Realm Browser open at the same time, the XCode will crash, since you will not be able to get Realm reference due to error.

To see the error use the catch statements instead of try! :wink:

do {
  let realm = try Realm()
  try! realm.write {
    realm.add(newMessages)
  }
  } catch {
     print(error.localizedDescription)
  }

From Realm Github issue tracker:

Realm v0.98.5, used by Realm Browser v0.98.5, included a change to the format of the lock file. As your application is using an older version of Realm you’ll need to use a corresponding version of the Browser that expects the older lock file format. You can find older versions on the Realm Browser’s releases page

.