I would like to be able to create an object and then add it to 2 or more arrays, dictionaries, etc, and if it's deleted from one, it should be deleted from the others automatically. So similar to this:
I've tried adding:
to the copy array but the count remains 1 (as expected, the NSValue is still there), but I can't figure out how to tell if what is returned from
is valid. In the very small test programs I'm trying I'm getting odd results where it's not nil but anything I do with it causes a crash. Or the object works as if it had been retained, just a lot of strange, inconsistent behavior.
If I could not even bother with the NSValue, that would be best. If it needs to be done, what would be the expected return from
if the object had been release elsewhere?
Code:
NSString *aString = [[NSString alloc] initWithString: @"Goodbye"];
NSMutableArray *masterList = [NSMutableArray arrayWithObject: aString];
NSMutableArray *copy = [NSMutableArray arrayWithObject: aString];
[aString release];
[masterList removeObjectAtIndex: 0];
NSLog(@"Copy Count: %lu", [copy count]); <- I'd like this to return 0
I've tried adding:
Code:
[NSValue valueWithNonretainedObject: aString]
Code:
[[copy objectAtIndex: 0] nonretainedObjectValue]
If I could not even bother with the NSValue, that would be best. If it needs to be done, what would be the expected return from
Code:
[[copy objectAtIndex: 0] nonretainedObjectValue]