Is force cast really bad and should always avoid it?

前端 未结 7 1293
无人及你
无人及你 2020-12-13 09:11

I started to use swiftLint and noticed one of the best practices for Swift is to avoid force cast. However I used it a lot when handling tableView, collectionView for cells

相关标签:
7条回答
  • 2020-12-13 10:06

    As described in some casting discussions, forcing the cast for tableView.dequeueReusableCell is ok and can/should be done.

    As answered on the Swiftlint Github site you can use a simple way to turn it off for the table cell forced cast.

    Link to Swiftlink issue 145

    // swiftlint:disable force_cast
    let cell = tableView.dequeueReusableCell(withIdentifier: "cellOnOff", for: indexPath) as! SettingsCellOnOff
    // swiftlint:enable force_cast
    
    0 讨论(0)
提交回复
热议问题