I have seen this code in Xcode editor :
How can I type these strings with different character position and font size ?
I have seen this code in Xcode editor :
How can I type these strings with different character position and font size ?
With these string literals, it's not a question of character position or font size. These are special unicode superscript/subscript characters. If you go to the macOS keyboard preferences and choose "Show keyboard and emoji viewers in menu bar", you'll have a new option in your menu bar "Show emoji & symbols". You can then, for example, type "2" in the searchbox and you'll then see subscript and superscript rendition in the "related characters" section:
So, this is not a general subscript/subscripting feature, but dedicated unicode characters for just a few common subscripts/superscripts (e.g. "2", "x", etc.).
Note, if you need more fine grained control over fonts, baseline adjustments, etc., many user interface controls support the use of attributed strings, e.g.:
let bigFont = UIFont.systemFont(ofSize: 20)
let smallFont = UIFont.systemFont(ofSize: 12)
let title = NSMutableAttributedString(string: "foo", attributes: [.font: bigFont])
title.append(NSMutableAttributedString(string: "bar", attributes: [.font: smallFont, .baselineOffset: 10]))
button.setAttributedTitle(title, for: .normal)
Yielding:
Or, as described in this answer, you can apparently also do:
let string = "foobar"
let range = NSRange(location: 3, length: 3)
let title = NSMutableAttributedString(string: string)
let superscript = NSAttributedStringKey(rawValue: kCTSuperscriptAttributeName as String)
title.addAttributes([superscript: 1], range: range) // Use 1 for superscript; use -1 for subscript
But your code snippet is clearly just using the predefined unicode superscript/subscript characters. These various programmatic approaches can be useful, though, if you need to render something that doesn't already exist in unicode.