Skip to content

Instantly share code, notes, and snippets.

@andr3a88
Last active February 22, 2019 09:18
Show Gist options
  • Save andr3a88/b55ca432639568330f987fc90f9ca9b5 to your computer and use it in GitHub Desktop.
Save andr3a88/b55ca432639568330f987fc90f9ca9b5 to your computer and use it in GitHub Desktop.
Reflection in Swift [Playground]
import UIKit
class UserSession {
let name: String = "Mario"
let id: String = "id_123123123"
let token: String = "s79s2waas9432j2jf23f2"
}
let userSession = UserSession()
/// Mirror currently doesn’t support writing any values, only reading them
let mirror = Mirror(reflecting: userSession)
for child in mirror.children {
print("Property name:", child.label ?? "")
print("Property value:", child.value)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment