migration - stv-ekushida/ios-design-guide GitHub Wiki

// Realmマイグレーション実行
static func migration() {
    
    // 0 = v1.0.0 ~
    let schemaVersion = UInt64(18)
    
    // Realmマイグレーション
    MigrationRealm().migration(schemaVersion: schemaVersion)
}

//中間データ削除
static func compactRealm(){
    let config = Realm.Configuration(shouldCompactOnLaunch: { totalBytes, usedBytes in
        let oneHundredMB = 100 * 1024 * 1024
        return (totalBytes > oneHundredMB) && (Double(usedBytes) / Double(totalBytes)) < 0.5
    })
    do {
        _ = try Realm(configuration: config)
    }catch let error as NSError {
    }
}