Realm Encryption Key for Realm Studio/Browser - swift

I'm currently [attempting] to use Realm in one of my applications; however, I'm unable to view the default.realm file in Realm Browser or Realm Studio, which I'm finding very inconvenient. Whenever I attempt to open the file I'm asked for an encryption key. I am not encrypting my realm files as far as I know.
All cocoapods are up to date as are Realm Browser and Realm Studio. I've created the file from new multiple times.
Any help would be greatly appreciated.
Further Information:
Podfile:
pod 'StitchSDK'
pod 'RealmSwift', '=10.0.0-beta.3' (this is directly from the MongoDB Realm tutorial)
Xcode version: 11.6,
Realm Studio: 3.11.0
I am attempting to open the auto-generated default.realm file stored at realm.configuration.fileURL (/Users/.../Library/Developer/CoreSimulator/Devices/9C9C5338-B831-45FC-BDDE-2311C4B6DE0D/data/Containers/Data/Application/F8149B26-D04F-4B1E-A923-BE0F5D229595/Documents/default.realm) and have deleted and regenerated this and its associated files to create it 'from new.'
When opening the file in Realm Studio (I've deleted Realm Browser since reading the comments) I receive the message: "Opening Realm files of format version 11 is not supported by this version of Realm". I am following a iOS SDK Tutorial for Realm in the MongoDB Docs to implement Realm in my app and it works: I'm just unable to view the file.
I do not have Filevault enabled and am developing for iOS. I'm not sure where to check for the sandboxing so it should be whatever the default is.
Thank you again!!

Whoa... pod 'StitchSDK' is not the correct podfile for working with MongoDB Realm. Stitch is a soon-to-be discontinued/depreciated product and is not needed as it's functionality is rolled into MongoDB Realm.
(Note this answer assumes you're sync'ing your data)
The confusion here is that Realm is in the 'middle' of a transition. The 'classic' product called Realm is currently 5.x and is what's referenced on the Realm.io website and is covered in the Getting Started Guide for 5.x
This version stores it's data locally first and synchronized with the Realm Object Server, and you can view that data using Realm Studio 10/11.x
The new product (unreleased and still in Beta at this time) is called MongoDB Realm and while they are similar, MongoDB Realm stores it's data locally first and in MongoDB Atlas (server)
Realm Studio "does not work" with MongoDB Realm. Your error is probably due to being sandboxed but that's another issue. Just don't use it at this time as it may corrupt your data. MongoDB Realm objects are a bit different than Realm objects so you may have weird issues.
To work with MongoDB Realm, you need to log into the MongoDB Realm website console, and either select Realm
to configure, work with your app specs, or to check the error log
or, select Atlas->Collections
to see your actual data.

Related

Opening Realm files of format version 11 is not supported by this version of Realm on Mac

Already saved my data to Local Realm DB. But can't read it with Realm Studio. Also can't read it with Realm Browser. Realm Browser asking for encryption key with 128-hex value.

Initialising Realm 5.0.x in Swift

I've been using Realm in an application for a number of months, accessing the data using Realm Browser. I have used a simple set-up without encryption:
do {
_ = try Realm()
} catch {
print("Error initialising realm, \(error)")
}
After upgrading to Realm 5.0.x I could no longer access the data - every time I tried to use the Realm Browser I was asked to enter the encryption key. I regressed to 4.4.x and all is OK again. I am using the latest version of the Browser available on the App Store.
Is this a new 'feature' in Realm 5, and should I now be using a different method to initialise the database?
If you've installed the new Realm 5.0 in your app, your database will be updated to match, format v10 - see the 5.0.0 Release Notes
Therefore, if you're using Realm Studio 10.0 or less, you won't be able to open the Realm.
Likewise if you open a Realm with Realm Studio 11.0, it will upgrade your Realm as well.
File format: Generates Realms with format v10 (Reads and upgrades all previous formats)
Realm Object Server: 3.21.0 or later.
Realm Studio: 3.11 or later.
APIs are backwards compatible with all previous releases in the 5.x.y series.
So bottom line is as of now, RealmSwift 5.0.x is a match for Realm Studio 11+. Once you have your Realm stuff on the same page, initialization is the same so your code is fine.
Note that for Realm Studio 11.0
When opening a file which is using an older format, you will get
prompted to upgrade (and optionally backup) the Realm file. NOTE: Once
the file has been upgraded, there is no way to downgrade it again and
it can only be used by the SDKs that support Realm file format v10.

Unable to update database to match the current model ... But only on one of two apps

I have two apps that are sharing the same EF Model/SQL DB. This morning, one of the two apps started giving me this message: Unable to update database to match the current model because there are pending changes and automatic migration is disabled
It's odd because:
When I run add-migration [name]; the migration file shows no updates needed.
The other app works without any issues using the same database. So I know the database and model aren't out of sync.
Rolling the app back before the latest deployment does not solve the issue.
Both apps work in test without any issues.
I temporarily renamed '__MigrationHistory' to see what was going on, and the app was attempting to recreate tables that where created years ago: There is already an object named '[table name]' in the database.
EDIT: I did not delete the files in the Migration folder, so that explains the above results.
Any idea what is going on? And how to fix it?
I attempted several other workarounds to no avail.
It was bizarre, my server said the object and db synced, my other apps said they synced, and when I deployed the app on a new server they synced.
I'm just marking this up as a bad Azure server.

Realm database in production

I developed an application using Realm database with user authentication via iCloud token.
Now I want to publish my application to the App Store and need to deploy Realm to the production.
My question is: What is the best and easiest way to deploy my Realm DB? I tried Realm Cloud and Azure with preinstalled image, but neither of those supported configuration of the Realm to communicate with iCloud. And all resources I found linked to non-existing Realm docs.

Getting Realm Version in Code

Two part question:
How does one get the currently installed version of Realm in code? Swift 3, macOS. I was unable to location any Realm.version property - perhaps I overlooked it.
In a related question
What is the solution to upgrade Realm to the latest version within a project? After updating CocoaPods to the latest, and refreshing, pod install doesn't appear to update Realm. I have 2.0.3 installed and 2.2.0 is available.
If you're embedding Realm Swift as a dynamic framework directly, the version number is contained in the framework's info.plist file. It should be possible to access the plist during runtime; there's a few answers on SO discussing this.
Since CocoaPods creates dynamic frameworks for Swift, the above approach of accessing the info plists should work, but if it doesn't there might be other ways to access versions of pods.
In any case, I would definitely recommend you review why you're wanting to check the version numbers of your libraries. It's better practice to check a framework's capabilities at runtime (eg, testing a class you need exists etc) than to directly use the version number.
For your second question, you need to run pod update RealmSwift to get CocoaPods to check for an updated version of Realm.