Initialising Realm 5.0.x in Swift - 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.

Related

Recently upgraded from Firebase 8.8 => 8.16 and now I have Firebase Instance ID error

I recently upgraded Firebase in my Swift app because I wanted to add App Check and I decided to update all the pods. Was only 8 minor releases 8.8 => 8.16. Now I am receiving
Firebase Instance ID is not compatible with Firebase 8.x+. Please
remove the dependency from the app.
I have removed my pods, cleaned, rebuilt, reinstalled.
I have restarted, cleaned, built.
I have removed App Check.
I have removed Messaging (which I've never used except for an experiment once).
I have no reference to Firebase Instance Id except in the FIR files which are Firebase's. Tried to follow the get started in the Firebase docs and they say use the Swift Package Manager (not sure if that was instead of CocoaPods?).
Any insight into this? It's obviously a new version issue, but would love to have to newest version for security vulnerability and any performance updates they've done. But my last resort will be to downgrade back to 8.8.

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.

Realm Encryption Key for Realm Studio/Browser

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.

SQLite not listed in Data Sources window

VS2015 Community is not showing SQLite in the list of available data sources in one place and showing it in the other.
If I click New Connection button in Server Explorer and click Change, I get the following list of Data Sources:
If I add a new item to my project > choose Entity Model > from existing database > New Connection, I get the following list of Data Sources:
How can I get SQLite in the New Connection data sources list?
Background
The problem started when my existing EDMX failed to load with the infamous error message
The Operation could not be completed: Invalid Pointer
This error can be fixed by deleting ComponentModelCache folder as described in this post. This method has worked for me in the past, but not this time. I finally decided to recreate the EDMX from scratch. Since then I'm facing this issue.
A few things that might give some hint:
I have recently installed VS2017 Community side-by-side with VS2015. VS2017 can open the existing EDMX just fine, but cannot do Update from Database, so I came back to VS2015.
I uninstalled and reinstalled System.Data.SQLite provider several times, thinking that this might be a registration issue. Didn't do any good.
Note that VS2017 support is not there yet on System.Data.SQLite's download page. I'm using the last available version that supports VS2015 (version number 1.0.104.0).
Good news is that the issue is fixed finally; at least for VS2015. Bad news is that I don't know what exactly did the trick. So I'll list down everything that I tried and maybe this could help someone in the future. These steps are not in any particular order.
Uninstall all SQLite packages from NuGet.
Uninstall Entity Framework package too.
Reinstall all these packages.
Remove and reinstall the latest version of SQLite provider (1.0.104.0 as of this writing).
Use VS2015 only. VS2017 is currently not supported by SQLite provider.
Clear ComponentModelCache folder and restart Visual Studio.
I found an easy solution, just install below extension from market place and Sqlite will be available to data source list
SQLite/SQL Server Compact Toolbox

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.