Skip to content

Instantly share code, notes, and snippets.

@FunkyMuse
Created March 18, 2020 12:53
Show Gist options
  • Save FunkyMuse/005d2b736d58c27174a30ab76785484f to your computer and use it in GitHub Desktop.
Save FunkyMuse/005d2b736d58c27174a30ab76785484f to your computer and use it in GitHub Desktop.
RealmKeyHelper
class KeyHelper<E : RealmModel?>(var classFrom: Class<E>) {
fun getIds(db: Realm, idName: String): IdModel {
val idHelper = RealmIdModel()
val currentID = db.where(classFrom).max(idName)
if (currentID == null) {
idHelper.nextID = 1
} else {
idHelper.nextID = currentID.toInt() + 1
}
currentID?.let {
idHelper.currentID = it.toInt()
}
return idHelper
}
}
data class RealmIdModel(var currentID:Int=0, var nextID:Int=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment