Arrays 如何在swift数组中使用minElement
我想得到行数最小的indexpath。我试图使用这段代码,但我不明白如何实现minElementArrays 如何在swift数组中使用minElement,arrays,swift,Arrays,Swift,我想得到行数最小的indexpath。我试图使用这段代码,但我不明白如何实现minElement try self.collectionView.indexPathsForVisibleItems().minElement(<isOrderedBefore: (NSIndexPath, NSIndexPath) throws -> Bool) 尝试self.collectionView.indexPathsForVisibleItems().minElement(Bool) 您可
try self.collectionView.indexPathsForVisibleItems().minElement(<isOrderedBefore: (NSIndexPath, NSIndexPath) throws -> Bool)
尝试self.collectionView.indexPathsForVisibleItems().minElement(Bool)
您可以给minElement
一块代码来帮助它比较两个无法与标准比较的东西您可以给minElement
一块代码来帮助它比较两个无法与标准比较的东西这里的类似问题:。这里的类似问题:。
struct MyIndex {
let row: Int
}
let array = [MyIndex(row: 3), MyIndex(row: 1), MyIndex(row: 2)]
// Swift 2
let firstIndex = array.minElement { a, b in
return a.row < b.row
}
// Swift 3
let firstIndex = array.min { a, b in
return a.row < b.row
}
self.collectionView.indexPathsForVisibleItems().minElement { a, b in
return a.row < b.row
}