Bark/Common/RealmConfiguration.swift
2024-12-11 17:17:09 +08:00

40 lines
1.3 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// RealmConfiguration.swift
// NotificationServiceExtension
//
// Created by huangfeng on 2024/5/29.
// Copyright © 2024 Fin. All rights reserved.
//
@_exported import RealmSwift
import UIKit
let kRealmDefaultConfiguration = {
let groupUrl = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.bark")
let fileUrl = groupUrl?.appendingPathComponent("bark.realm")
let config = Realm.Configuration(
fileURL: fileUrl,
schemaVersion: 15,
migrationBlock: { migration, oldSchemaVersion in
switch oldSchemaVersion {
case 0...13:
migration.enumerateObjects(ofType: Message.className()) { oldObject, newObject in
guard let obj = oldObject else {
return
}
guard let isDeleted = obj["isDeleted"] as? Bool else {
return
}
// isDeleted
if isDeleted, let newObject {
migration.delete(newObject)
}
}
default:
break
}
}
)
return config
}()