How to Correctly Use Shouldcompactonlaunch in Realmswift

How to correctly use shouldCompactOnLaunch in RealmSwift

So the solution for me was to create to configs. The configs are identical except of the shouldCompactOnLaunch block. This config with the shouldCompactOnLaunch I just use once at app launch, so it does not get triggered every time.

Here is the link to the Realm github issue

If the compaction fails the app will continue using the uncompacted version of the database.

How can I fix my Realm problem for device

All of that Realm code is correct, so I don't believe there's any problem with how you're creating new Realm objects.

However, I think you've got how containerURL(forSecurityApplicationGroupIdentifier:) works a little confused.

In this example, you're providing your app's bundle identifier to that API, but that's actually not what it expects. It wants a "group identifier" which specifies the name of a shared directory between an app and its extensions, that you define under "App Groups" in your app's Capabilities setting (More info on that is on Apple's developer site).

Looking at the source code, it looks like you've already set up an app group called group.simplemarket.

So if you change

private let appID = "com.karinyfreitas.SimpleMarket"

to

private let appID = "group.simplemarket"

That should fix all of your problems here. Welcome to Stack Overflow!

Realm: 'Cannot set a default configuration after using per-path configuration methods.' Swift 2

It looks as if you're calling one of the following deprecated functions:

setSchemaVersion(_:atPath:migrationBlock:)
// or
Realm.setEncryptionKey(_:forPath:)

along side your Realm.Configuration usage. These methods are incompatible with Realm.Configuration so you should move entirely to Realm.Configuration to avoid these issues.

These deprecated methods will be removed completely in the next major release of Realm Objective-C and Realm Swift.

Realm file size is too large

as bcamur sad,

the Realm file will maintain its size on disk to efficiently reuse
that space for future objects

but there is also written

The extra space will eventually be reused by future writes, or may be
compacted — for example by calling
Realm().writeCopyToPath(_:encryptionKey:).

and

call invalidate to tell Realm that you no longer need any of the
objects that you’ve read from the Realm so far, which frees us from
tracking intermediate versions of those objects. The Realm will update
to the latest version the next time it is accessed

Test in-memory Realm migration

A migration inherently cannot be run on an in-memory Realm. In-memory Realms only exist until they are closed, and a migration cannot be run on a Realm which is already open. You will need to use a Realm on disk to test migration logic (and just delete the Realm at the end of the test).



Related Topics



Leave a reply



Submit