Separating Data Source to another class in Swift

前端 未结 3 698
时光取名叫无心
时光取名叫无心 2020-12-13 20:21

I\'m trying to keep my view controllers clean as described in this article objc.io Issue #1 Lighter View Controllers. I tested this method in Objective-C and it works fine.

3条回答
  •  被撕碎了的回忆
    2020-12-13 20:54

    Extending the accepted answer by "ayalcinkaya", which explains the how but not the why:

    Most probably what is happening is that your TableDataSource is being deallocated as tableview.dataSource is a weak reference, that is why creating a property solves the problem, as it creates a strong reference and avoids the dataSource delegate being deallocated.

提交回复
热议问题