Add this to any Struct if you want a string of all the optional values that actually have defined content.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var whatDoIHave:String { | |
let mirror = Mirror(reflecting: self) | |
var itemsToDisplay:[String] = [] | |
for child in mirror.children { | |
//print("key: \(child.label), value: \(child.value)") | |
if child.value is ExpressibleByNilLiteral { | |
let typeDescription = object_getClass(child.value)?.description() ?? "" | |
if !typeDescription.contains("Null") && !typeDescription.contains("Empty") { | |
itemsToDisplay.append(child.label ?? "no_key") | |
} | |
} | |
} | |
let returnString = itemsToDisplay.count > 0 ? "Optionals Available: \(itemsToDisplay.joined(separator: ", "))" : "" | |
return returnString | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment