tags:

views:

111

answers:

1

Short description of my setup:

There is an SQLObject base class which has an integer rowId. it implements isEqual by comparing its class and its rowId:

return [self isKindOfClass:[otherObject class]] && self.rowId == otherObject.rowId;

It implements hash by XORing its class with its rowId:

return [[self class] hash] ^ self.rowId;

All objects are stored in an NSMutableSet so that if they are requested from the DB again, the same object is used rather than creating a new one. When releasing an SQLObject, it checks if the retainCount is exactly 1, and if so, removes it from the set, thus deallocating it.

The problem is, it doesn't find the object when it's trying to remove it from the set. The rowId never changes, nor does the class, obviously, so neither the hash nor the isEqual change throughout the object's life. What's going on? Does anybody have any ideas as to why it might not be finding it?

If I change the collection to an NSMutableArray, it does find it.

A: 

I never came up with a good solution to this. Instead I've come up with a bit of a different approach:

Each SQL Object subclass has its own NSDictionary. The key is an NSNumber of the object's rowId, and the value is a weak link to the SQL Object. When the SQL Object is deallocated, its weak link is removed from the dictionary.

Ed Marty