I would like to understand how Swift and objective-c handle passing around nil references. I know that I cannot add nil to an Objective-C mutable array.
How nil is handled in the following scenario:
Does Objective-C class keep functioning, or does it crash when trying to iterate over the array and getting a nil reference?
Unless you are using NSPointerArray
, when you add the object to an array the array will hold a strong reference to it, preventing the object from being released.
Only after the object is removed from the array, or the array itself is released will the object be eligible for deallocation.
This means that the array cannot be left holding a nil reference.