mozilla/firefox-ios — pull request #50 by thebnich (2014-12-16 18:59:15+00:00)
Title: Bug 1112228 - Fix tabbed browsing issues

I'm still not quite used to Swift's copy-on-write behavior for arrays, and there are several bugs in TabTrayController that can cause the tabs arrays to get out-of-sync between the delegate and the data source. I got halfway there by using inout in the initializers, but then they end up getting copied immediately after that when the initializer assigns them [1]. That means the tabs arrays in the delegate/data source are still copies -- not references -- to the arrays given to them, so when the data source changes the array [2], that change isn't reflected in the delegate array.

I think the most straighforward fix to this is to implement all of the protocols in TabTrayController so they have access to the same shared data structures. I originally kept the delegate/data source classes separate since I was playing around with the BVC owning them, but there's no need for the separation now.

[1] https://github.com/mozilla/firefox-ios/blob/bdedf9ed54fa4ffdf2e696704019d379ef244fa1/Client/Frontend/Browser/TabTrayController.swift#L84
[2] https://github.com/mozilla/firefox-ios/blob/bdedf9ed54fa4ffdf2e696704019d379ef244fa1/Client/Frontend/Browser/TabTrayController.swift#L102