Created
January 15, 2015 23:08
-
-
Save rlac/69b5f6eeb55c3d36d0bc to your computer and use it in GitHub Desktop.
Parcelable creator convenience function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.os.Parcelable | |
import android.os.Parcel | |
import kotlin.InlineOption.ONLY_LOCAL_RETURN | |
public inline fun creator<reified T : Parcelable>( | |
inlineOptions(ONLY_LOCAL_RETURN) createFromParcel: (Parcel) -> T?): Parcelable.Creator<T> = | |
object : Parcelable.Creator<T> { | |
override fun createFromParcel(source: Parcel): T? = createFromParcel(source) | |
override fun newArray(size: Int): Array<out T?> = arrayOfNulls(size) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.os.Parcelable | |
import android.os.Parcel | |
import kotlin.platform.platformStatic | |
class Test(var int: Int, var string: String) : Parcelable { | |
override fun describeContents(): Int = 0 | |
override fun writeToParcel(dest: Parcel, flags: Int) { | |
dest.writeInt(int) | |
dest.writeString(string) | |
} | |
class object { | |
platformStatic val CREATOR = creator { p -> Test(p.readInt(), p.readString()) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment