``` val http200Status = object { val statusCode = ...
# announcements
s
Copy code
val http200Status = object { val statusCode = 200; val description = "OK" }

println("The status code is ${http200Status.statusCode}")
👆 1
👍 1
w
yes, but only available for local variables or private properties, right?
s
Indeed
I’m not sure if swift tuples have access to the named properties outside of those scopes, though - haven’t used them myself
w
Swift can do it 😣
m
If you want access like that, you can use a map. Otherwise, I tend to favour concrete classes anyway. The whole point of using a static language, right?
s
I think the point of the Swift implementation is that (somehow) you get the best of both worlds
I wouldn’t say that that’s the whole point of using a static type system ¯\_(ツ)_/¯
m
Although thinking about it, it's not really a map, is it as I would guess the names are known to the compiler. So it's sort of an easy data class. I'd have to see more examples of usage as the one provided doesn't feel like a good use case. I'd define an httpstatus class with those properties and use it for 200, 404 etc.
j
I don't think there is any real-life use case where such tuples could be somehow superior to small-ish data classes. But it seems like a nice feature for readability, instead of the old first/second/destructuring
g
Why not just use data class for this?
Copy code
data class HttpStatus(val statusCode: Int, description: String)

val http200Status = HttpStatus(200, "OK")

println("The status code is ${http200Status.statusCode}")
// Prints "The status code is 200"
println("The status message is ${http200Status.description}")
j
Convenience for small-scope pair operations? Wherever data class is kind of an overkill but names could still be useful
g
For small local scope you can use
object { }
👍 3