RosettaCodeData/Task/Break-OO-privacy/Swift/break-oo-privacy.swift
2023-07-01 13:44:08 -04:00

11 lines
261 B
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)")
}