据我了解,仅在@StorIOSQLiteCreator
主构造函数上可以使用Kotlin
注释。就我而言,我有Parcelable
数据类,其中有一些但不是全部字段都存储在db中。我想知道是否有一个为storio创建辅助kotlin
构造函数的选项,该选项将使用存储字段的完整列表或使用主构造函数,而不用@StorIOSQLiteColumn
这就是我认为解决方案的外观:
@Parcelize
@StorIOSQLiteType(table = "tweets")
data class Tweet @StorIOSQLiteCreator constructor(
@StorIOSQLiteColumn(name = "_id", key = true) var id: Long,
@StorIOSQLiteColumn(name = "author") val author: String,
var content: List<ParcelableButNotStoredObject>? = null
) : Parcelable
这就是我现在可以实现目标的方式:
@StorIOSQLiteType(table = "tweets")
data class Tweet @StorIOSQLiteCreator constructor(
@StorIOSQLiteColumn(name = "_id", key = true) var id: Long,
@StorIOSQLiteColumn(name = "author") val author: String
) : Parcelable {
var content: List<ParcelableButNotStoredObject>? = null
constructor(parcel: Parcel) : this(
parcel.readLong(),
parcel.readString()) {
content = parcel.createTypedArray(ParcelableButNotStoredObject.CREATOR).toList()
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeLong(id)
parcel.writeString(author)
parcel.writeTypedArray(content?.toTypedArray(), 0);
}
override fun describeContents(): Int = 0
companion object CREATOR: Parcelable.Creator<Tweet> {
override fun createFromParcel(parcel: Parcel): Tweet = Tweet(parcel)
override fun newArray(size: Int): Array<Tweet?> = arrayOfNulls(size)
}
}