I have an iOS/swift project with two views that both use CBLUITableSource to represent two different lists of CBLModel objects, games and players. Each type of CBLModel object holds a reference to another POSO which is lazily calculated because its expensive to do so. Its the stats for the game or the player. Both of my view controllers implement
couchTableSource(source: CBLUITableSource!, cellForRowAtIndexPath indexPath: NSIndexPath) and in both cases they call CBLModel(forDocument: row.document) to get an instance of the model object.
On the game list, I get the behaviour I want which is that each game instance is instantiated only once and I only ever have to calculate the stats once.
However on the players list, the modelObjects seem to get garbage collected because I frequently get new instances of player objects and have to recalculate the stats. The only obvious difference between the two lists is that on the game list I do:
let game = Game(forDocument: row.document)
and on the players list I do:
let player = CBLModel(forDocument: row.document) as Player
because there are different types of players and I want the CBLModelFactory to figure out which one it is.
Has anyone seen this, or have any idea why this is happening?