How to make a weak set of links in Swift

NSSet contains strong references to its objects, so the Objective-C solution should have used NSHashTable.weakObjectsHashTable () a la

NSHashTable* mySet = [NSHashTable weakObjectsHashTable]; [mySet addObject:anyOldObject]; [mySet count]; //returns 1 [mySet containsObject:anyOldObject]; //returns true 

in swift however this does not work

 var mySet = NSHashTable.weakObjectsHashTable() mySet.addObject(anyOldObject) mySet.count //returns 1 mySet.containsObject(anyOldObject) //returns false 

What am I missing? Or is it a mistake?

+7
swift xcode6 foundation
source share
1 answer

In Xcode6b5 and using a string like anyOldObject, I can see that the return is happening. There were some bugs in 6b4 that prevented the return of additional values โ€‹โ€‹in the interpreter, which meant that they were aggressively cleaned - it could be a problem like this, which has the same effect here. Itโ€™s worth trying again to see if you have the same behavior in the latest beta.

0
source share

All Articles