I don't think you are a really asking about immutable arrays here as you aren't invoking any methods on the array itself, so it's mutability cannot be an issue. The immutable attribute of the subviews
array is how the view has decided to present the list to you. It's got nothing to do with how sub-views interact with parent views.
You appear to be confused about why a subview can remove itself from the parent view and you cannot; this is simply because the subview is a UIView
-subclass and the parent view is a UIView
-subclass and therefore the subview has access to all of the internal variables of the parent and can do whatever it likes to the parent. You cannot. This is deliberate as you don't know the intricacies of the view hierarchy (and don't want to), where as the UIView
obviously does.
Another interesting aspect of the code you posted is that often getting an element in an array to remove itself from the array while you are enumerating it, will cause an exception. In this particular case, however the subviews
array you receive from the view is a copy
of the original (an immutable copy) and therefore getting the subview to remove itself from the parent view will not affect this array and the enumeration will not falter. Thanks to Christopher Kevin Howell for pointing this out, as I missed it completely, first time round.