1

I want access to string part or label part of a variable/constant in Xcode, look this code:

let name: String = "Dude"

print("name" + ":", name) // print result --->  name: Dude

As you can see I am using "name" for having name in print, which I like just be access the label of name in Xcode, like this:

let name: String = "Dude"
let age: Int = 45

print(name.label + ":", name) // print result --->  name: Dude
print(age.label + ":", age)   // print result --->  age: 45
  • 1
    Check this: https://stackoverflow.com/q/36943853/1187415 and this: https://stackoverflow.com/q/26005654/1187415 – Martin R Feb 03 '22 at 20:13
  • @MartinR: Thanks a lot, the second one had some answers, the first one does not provide a way. –  Feb 03 '22 at 20:26
  • @MartinR: I noticed all the ways in second link need a class to be able working, so in my case in question there is no way. because i do not have a class, I just have a constant. –  Feb 03 '22 at 20:35
  • I was thinking to extend String or Int with label computedProperty but I cannot use those way to define a variable inside a class in run time to compute the label. –  Feb 03 '22 at 20:37
  • Unless I am mistaken, it is not possible for a variable which is not member of a class (for reasons explained in the first link). – Martin R Feb 03 '22 at 20:43
  • That is right, that would be great if it was possible for stand alone variable or constant, then I could make an extension for String and Int. :( –  Feb 03 '22 at 20:48

0 Answers0