I am learning some swift runtime hackery, I want to tamper with a class instance variable of type String. The Swift 5 class is defined as below:
class MyClass {
var foo: String
var bar: String
}
on iOS for ARM64 each instance variable is layed out sequentially in memory, but they occupy 2 words (16 bytes). I don't know the purpose of the first word, it seems to be a tagged pointer which includes the length of the string. The next pointer is a reference to StringStorage, internally that class is named "Swift.__StringStorage". Is it safe to replace this pointer by an instance of NSString?
You would need to also edit the flags in the first word to tell String that it has a different type of backing store now. And, just in general, this is not a safe or supported thing to do.