简体   繁体   中英

Swift 3.0 migration error: Type 'Element' constrained to non-protocol type 'IndexPath'

I am trying to migrate my code base to swift 3.0 using xCode. There are few issues which I am not able to understand.

Issue: Type 'Element' constrained to non-protocol type 'IndexPath'

在此输入图像描述

In left side of error navigation panel it's shows only below errors. I am not able to understand for which line of code or branch of code causes the error.

在此输入图像描述

Can anyone help me to solve this please.

UPDATE

After struggling a lot I am stuck at these issues.

在此输入图像描述

UPDATE

Thank you all for your help. Now I faced only the following issues.

在此输入图像描述

Few of you are asking to post the source code but Xcode didn't show any kind of warning or error on pages. There are few generics

private extension Array where Element: IndexPath {

    func indexOf(_ indexPath: IndexPath) -> Int {
        var counter = 0
        for object in self {
            if object.section == indexPath.section && object.row == indexPath.row {
                return counter
            }
            counter += 1
        }
        return 0
    }
}


fileprivate func < <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
  switch (lhs, rhs) {
  case let (l?, r?):
    return l < r
  case (nil, _?):
    return true
  default:
    return false
  }
}

You can use a specific type with a different syntax:

extension Array where Element == IndexPath {

As opposed to the more historic syntax for protocols:

extension Array where Element: Indexable {

Previously you could / had to shuffle around problems by creating a protocol, something like:

protocol Indexable {
    var row: Int { get }
    var section: Int { get }
}

extension IndexPath: Indexable {}

extension Array where Element: Indexable {
    ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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