I’d like to assign nil to an object, which is an ivar, passed in as a parameter to a method, something like this.
- (int)trashObjectPassedIn:(Banana* banana) {
banana = nil;
return 42;
}
Of course, if I call it like this: [self trashObjectPassedIn:oldBanana]; oldBanana is untouched – only the local parameter is assigned.
Is there any way I can assign nil to the original object?
I suggest finding an alternative approach. Your trashObjectPassedIn is passed a reference to the banana. You can nil that, but nothing will happen to the actual banana.
If you want the banana to be deleted (and you’re using ARC) then you should nil the property or member variable that owns the banana.