| ▲ | comrade1234 4 hours ago | |||||||||||||
Isn't NSMutableArray a subclass of NSArray in a few languages? | ||||||||||||||
| ▲ | bartvk 3 hours ago | parent | next [-] | |||||||||||||
Good one, yes. It was like that in Objective-C, and in the early versions of Swift. I know you know this, but it's useful to summarize for myself: 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). | ||||||||||||||
| ||||||||||||||
| ▲ | catoc 3 hours ago | parent | prev [-] | |||||||||||||
Yes, that’s ObjC, any NSMutableArray is an NSArray (and an NSObject) - classes passed by reference. Swift is completely different. Standard arrays are structures, always mutable - value types passed by value | ||||||||||||||