var name: String? = "name"
if let copyname = name {
print(copyname)
}
In this code, are name and copyname allocated in two different memory?
String is a special case which uses copy-on-write optimisations so the underlying buffer can
be shared by different copies of a string.
Note the use of can
as there are other factors that could impact this eg small string optimisations, bridging, compiler optimisations, etc.
https://developer.apple.com/documentation/swift/string#Performance-Optimizations