Search code examples
cocoa-touchpropertiesnsindexpath

Is it OK for my NSIndexPath property to remain unset?


When I want to add or edit values in my table, I use a modal view controller. When editing, I set an NSIndexPath property on the modal view controller so that it will know which item to update. But when adding a new item, there is no NSIndexPath value to send, so the property remains unset.

Is there any problem with leaving a property unset like this? It doesn't allow me to set it as "nil".


Solution

  • First, why can't you set it to nil? That shouldn't be a problem.

    Second, when the memory that an object occupies is zeroed out on allocation. That means that all instance variables are set to 0, NULL, nil (which is all just 0) when you create an object. So unless you modify an instance variable (or a property that refers to an ivar), it will be zero.