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 {
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With