A StaticString is a non-heap allocated "string" whose value is a constant known at runtime, referenced by an UnsafePointer<UInt8>.
They're often created and returned when using # function arguments for logging, etc..
So, let's look at something like...
struct StringKey: Hashable {
let key: String
internal init(key: StaticString = #function) {
...
}
}
class Test {
var item3: StringKey {
StringKey()
}
}
So, if I call item3 from somewhere in Test, the value of key
provided by the default #function
argument in the StringKey constructor is "item3", accessible via the utf8Start
value of StaticString, The string value (item3) will always be the same for the lifetime of the program.
And will have the same value every time the variable is called and a new StringKey is returned.
Which leads to the question at hand:
Since it's a constant value, created at compile time and loaded with the rest of the linked code, will the corresponding utf8Start
pointer value likewise always be the same through the lifetime of the program?