0

In my Firestore I have a "employee" node that looks like that :

enter image description here

I'm asigning that node to a "User" object in Kotlin:

object User {
    val firstName: String = "";
    val lastName: String = "";
    val employeeId:String="";
    val city:String = "";
    val email:String="";
    val salary:Number=0;
    val imgUrl:String="";
    val employmentStatus:String="";
    val employmentDate: ??????
}

My question is what type should "employmentDate" be? In Typescript I'm doing just:

employmentDate:{day:number,month:number,year:number}

can I do something similar in Kotlin?

1 Answer 1

2

Don't use object. object are singleton classes in kotlin. Instead use normal classes in kotlin and use composition.

class User{
val firstName: String = "";
val lastName: String = "";
val employeeId:String="";
val city:String = "";
val email:String="";
val salary:Number=0;
val imgUrl:String="";
val employmentStatus:String="";
var employmentDate: EmploymentDate = EmploymentDate()

class EmploymentDate{
val day:Int=0
val month:Int=0
val year:Int=0
}
}
Sign up to request clarification or add additional context in comments.

5 Comments

-ty sir well I want to be able to call "User.firstName" from anywhere in my aplication and get firstName tha has been assign from firestore so I need a object/singelton for that - thank you again for a code above (y)
You can store it in shared preferences or create a custom singleton class wrapper around it.
could You please clearified " custom singleton class wrapper around it" - like You said object is like a singeltone in kotlin so that's what I just did ,I put my User in a singeltone-guessing I am missunderstanding something here...:S
object MySingleton { lateinit var myUser: User } /* Somewhere after getting the data from the FireStore */ MySingleton.myUser=user After this you can access using your singleton class anywhere.
great - now I uderstand -that was to big help sig -ty (y)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.