繁体   English   中英

有人可以帮我解决这个警告:冗余一致性约束 'T':'ReusableView'? 我到处搜索,但没有发现任何帮助

[英]Can someone help me to fix this warning: Redundant conformance constraint 'T': 'ReusableView'? I search everywhere and I found nothing helpful

有人可以帮我解决这个警告吗?

冗余一致性约束“T”:“ReusableView”

我到处搜索,但没有发现任何帮助。

import UIKit

extension UICollectionView {

    func register<T: UICollectionViewCell>(_: T.Type) where T: ReusableView, T: NibLoadableView {
        //warning: Redundant conformance constraint 'T': 'ReusableView'

        let nib = UINib(nibName: T.nibName, bundle: nil)
        register(nib, forCellWithReuseIdentifier: T.reuseIdentifier)
    }

    func dequeueReusableCell<T: UICollectionViewCell>(forIndexPath indexPath: IndexPath) -> T where T: ReusableView {
        //warning: Redundant conformance constraint 'T': 'ReusableView'

        guard let cell = dequeueReusableCell(withReuseIdentifier: T.reuseIdentifier, for: indexPath as IndexPath) as? T else {
            fatalError("Could not dequeue cell with identifier: \(T.reuseIdentifier)")
        }
        return cell
    }
}

extension UICollectionViewCell: ReusableView {}

首先,编译器警告约束是多余的。 这不是错误。 你可以保持原样。

如何修复警告?

您的 UICollectionViewCell 已经在代码中的某处进行了扩展以符合ReusableView协议。

这就是您不必再次应用此约束的原因。

func register<T: UICollectionViewCell>(_: T.Type) where T: NibLoadableView {
}

它对我的应用程序的行为有影响吗?

这对应用程序的行为没有影响,因为删除的约束如警告中所述是redundant的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM