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 an开发者_开发技巧y problem with leaving a property unset like this? It doesn't allow me to set it as "nil".
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.
It should be ok. The property is, I think, initialized to nil. So in your modal view controller's dealloc
method, invoking release
on a nil object is a no-op.
Alternatively, to be safe, in your modal view controller's init method, set the property to nil there, e.g. self.myIndexPath = nil. That should work.
精彩评论