Swift is completely different. Standard arrays are structures, always mutable - value types passed by value
Basically inheritance is the wrong tool for this kind of stuff. NSMutableArray inherits from NSArray, so it can be passed to anywhere NSArray is expected (upcasting).
So you design your classes and expect them to be immutable, but you can't use NSArray anywhere. Because otherwise, it'll be mutable after all. You can do a runtime check as a workaround.
(I truly believe OOP should only be taught in computer science as a relic).
https://commonplacefacts.com/2022/07/27/principia-mathematic...
In C# ReadOnlyCollection<T> and ImmutableArray<T> are two completely different things for this exact reason.
gus_massa•12h ago