1

I have a global variable like:

let myVar:Bool = true

I want to get the actual name (as String) of the variable. Something like:

print(myVar.name)

should print the myVar string.

Note: I found this solution but it does not deal with global variables. It will only work with classes & structs it seems.

Thanks!

Community
  • 1
  • 1
Confused
  • 3,846
  • 7
  • 45
  • 72
  • 1
    Why don't just create something like that: let myVarString: String = "myVar" ? Why do you need this feature ? – damdamo Jul 25 '19 at 14:20
  • Maybe this topic will be useful for you: [C# equivalence of "name of" in Swift](https://stackoverflow.com/questions/47891310/is-there-a-swift-equivalent-of-cs-nameof-function-to-get-a-variable-or-mem?noredirect=1&lq=1) – damdamo Jul 25 '19 at 14:33
  • @damdamo Sadly, reflection concept will only work with class objects :( – Confused Jul 25 '19 at 14:50
  • In which context do you need it ? Do you have an example ? – damdamo Jul 26 '19 at 07:31

0 Answers0