The RLMRealmConfiguration header RLMRealmConfiguration has additional information:
@property (nonatomic, copy, nullable) RLMShouldCompactOnLaunchBlock shouldCompactOnLaunch;
Admittedly, we should make it more apparent in the documentation on the site that this block should only be called the first time an instance of Realm is created that represents a specific Realm file.
If you definitely see that this block is being called for the same Realm file several times, please open the problem on the Realm Cocoa GitHub page with detailed playback instructions.
Once you have created an instance of Realm with a specific Configuration , it is usually best to avoid mutating this configuration after the fact. You should not create two different Configuration objects, one with a compaction unit and one without it. Realm internally caches Realm instances based on its Configuration , so you can get unpredictable behavior.
The seal must not be interrupted. The only serious scenario when this becomes a problem will be that your device is already on the verge of running out of hard disk space. Depending on how much empty space was in this kingdom, compacted kingdoms are usually usually much smaller, so the entire operation will not require twice the size of the vault. In iOS, if the system detects that its storage space is low, this will cause a โCleanupโ phase, in which the Caches directory of other applications will be cleaned Caches , which in the vast majority of cases alleviates the problem that is sufficient to complete the process.
If all this fails, an attempt to perform the compaction will raise an exception; which your error handling code should catch.
source share