Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 如何在swift数组中使用minElement_Arrays_Swift - Fatal编程技术网

Arrays 如何在swift数组中使用minElement

Arrays 如何在swift数组中使用minElement,arrays,swift,Arrays,Swift,我想得到行数最小的indexpath。我试图使用这段代码,但我不明白如何实现minElement try self.collectionView.indexPathsForVisibleItems().minElement(<isOrderedBefore: (NSIndexPath, NSIndexPath) throws -> Bool) 尝试self.collectionView.indexPathsForVisibleItems().minElement(Bool) 您可

我想得到行数最小的indexpath。我试图使用这段代码,但我不明白如何实现minElement

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
}