# Kotlin equivalent of Swift's struct?

**URL:** https://discuss.kotlinlang.org/t/kotlin-equivalent-of-swifts-struct/2232
**Category:** Support
**Created:** [January 20, 2017, 1:32pm UTC](https://discuss.kotlinlang.org/t/kotlin-equivalent-of-swifts-struct/2232 "2017-01-20T13:32:58Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Deeyennay](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/deeyennay/32/2290_2.png) [@Deeyennay](https://discuss.kotlinlang.org/u/Deeyennay)
#### Post date: [January 20, 2017, 1:32pm UTC](https://discuss.kotlinlang.org/t/kotlin-equivalent-of-swifts-struct/2232/1 "2017-01-20T13:32:58Z")

</div>

In Swift, I like to use structs to store a bunch of constants like a certain integer or color I would like to use throughout the app. Some of these have to be determined at runtime. What would be the Kotlin equivalent of this?

Do I have to create a data class with a dummy parameter with a default value, and store the constants in that class?

Do I have to create a normal class with a companion object and store constants in there? If so, how does that affect performance? Does it still instantiate the class if I use it many times?

What if I create a class with no companion object, but several other objects stored in it instead, each with their own set of constants. How does this affect performance?

Do I create an object and store constants in there? Is it automatically a singleton object?

Or is there a better way to go about this?

---

<div class="post-metadata">

### Author: ![mplatvoet](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/mplatvoet/32/7121_2.png) [@mplatvoet](https://discuss.kotlinlang.org/u/mplatvoet)
#### Post date: [January 20, 2017, 1:50pm UTC](https://discuss.kotlinlang.org/t/kotlin-equivalent-of-swifts-struct/2232/2 "2017-01-20T13:50:56Z")

</div>

I think you are looking for an [object declaration](https://kotlinlang.org/docs/reference/object-declarations.html) which is in essence a Singleton.

Though I wouldn’t compare it to a `struct` since that has a different meaning and behaviour in most other languages.

---

<div class="post-metadata">

### Author: ![Deeyennay](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/deeyennay/32/2290_2.png) [@Deeyennay](https://discuss.kotlinlang.org/u/Deeyennay)
#### Post date: [January 20, 2017, 4:25pm UTC](https://discuss.kotlinlang.org/t/kotlin-equivalent-of-swifts-struct/2232/3 "2017-01-20T16:25:44Z")

</div>

Thanks for your help! I was looking for a way to determine constants at runtime, to then use them throughout the app. I believe an object declaration will do the trick for me. Thank you!

---

<div class="post-metadata">

### Author: ![dalewking](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/dalewking/32/1496_2.png) [@dalewking](https://discuss.kotlinlang.org/u/dalewking)
#### Post date: [January 21, 2017, 7:41pm UTC](https://discuss.kotlinlang.org/t/kotlin-equivalent-of-swifts-struct/2232/4 "2017-01-21T19:41:09Z")

</div>

And realize that you don’t have to put those constants in anything. They can be at the top level in Kotlin.

---

<div class="post-metadata">

### Author: ![Deeyennay](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/deeyennay/32/2290_2.png) [@Deeyennay](https://discuss.kotlinlang.org/u/Deeyennay)
#### Post date: [January 22, 2017, 2:35am UTC](https://discuss.kotlinlang.org/t/kotlin-equivalent-of-swifts-struct/2232/5 "2017-01-22T02:35:37Z")

</div>

Thanks for the tip!
