Tap*_*Pal 15 migration ios swift swift3
我正在尝试使用xCode将我的代码库迁移到swift 3.0.我无法理解的问题很少.
问题: Type 'Element' constrained to non-protocol type 'IndexPath'
在错误导航面板的左侧,它仅显示错误.我无法理解哪行代码或代码分支导致错误.
任何人都可以帮我解决这个问题.
UPDATE
经过艰苦的努力,我陷入了这些问题.
UPDATE
感谢大家的帮助.现在我只面临以下问题.
很少有人要求发布源代码,但Xcode没有在页面上显示任何类型的警告或错误.仿制药很少
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
}
}
Run Code Online (Sandbox Code Playgroud)
Wai*_*ain 86
您可以使用具有不同语法的特定类型:
extension Array where Element == IndexPath {
Run Code Online (Sandbox Code Playgroud)
与协议的更具历史性的语法相反:
extension Array where Element: Indexable {
Run Code Online (Sandbox Code Playgroud)
以前你可以/不得不通过创建协议来解决问题,例如:
protocol Indexable {
var row: Int { get }
var section: Int { get }
}
extension IndexPath: Indexable {}
extension Array where Element: Indexable {
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7736 次 |
| 最近记录: |