Break OO privacy: Difference between revisions

m (Omit from Rust)
Line 1,172:
# Access private attributes
say obj{:private}; #=> "secret"</lang>
 
=={{header|Swift}}==
Swift reflection provides a Collection of label-value pairs for struct properties
<lang Swift>struct Example {
var notSoSecret = "Hello!"
private var secret = 42
}
 
let e = Example()
let mirror = Mirror(reflecting: e)
 
if let secret = mirror.children.filter({ $0.label == "secret" }).first?.value {
print("Value of the secret is \(secret)")
}
</lang>
{{out}}
<pre>Value of the secret is 42</pre>
 
=={{header|Tcl}}==
Anonymous user