This one "feature" has caused more bugs in my Swift code than anything else. For frequently used types I can remember whether they are structs or classes. But for new code written by others or my own code when the design isn't quite settled yet, I need every syntactical clue I can get to avoid mistakes.
This is not the only place where Swift goes with "clean" syntax at the expense of local clues that help readability. Result builders are another example.
Also, it's pretty straightforward to create a reference type of a value type if you end up need it: Just create a new type that is a reference type and has the value type as a property. No?
A big part of the semantics in the language is “copy on write”.
var count = 0
let closure = {
count += 1
print("Current count=", count)
}
closure() // Current count= 1
closure() // Current count= 2
closure() // Current count= 3
let capturedVariableClosure = { [count] in
print("Current count=", count)
//count += 1 // syntax error, count is const variable. Use var count in capture group
}
capturedVariableCount() // Current count= 3
closure() // Current count= 4
capturedVariableCount() // Current count= 3For example, there are something like eight classes exposed in the minimal swift standard library, representing concepts like managed buffers, singletons like the MainActor, and for implementing concepts like task-local values. These are all examples of types which do not lend themselves to being value types.
Once you start getting to file and network I/O, or interfacing with Objective-C, you start to see the percentage of reference types climb.