Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.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
Ios 如何获取二维数组的行索引?_Ios_Arrays_Swift_Multidimensional Array_Swift3 - Fatal编程技术网

Ios 如何获取二维数组的行索引?

Ios 如何获取二维数组的行索引?,ios,arrays,swift,multidimensional-array,swift3,Ios,Arrays,Swift,Multidimensional Array,Swift3,我是Swift新手,我正在使用2D数组进行比较,一旦条件为真,我需要获取行索引,但我得到了一个错误状态,无法使用类型为(of:array)的参数列表调用索引。 我的代码: var entryCoordinate: [[Float]] = [[130.6,61.0],[167.5,61.0],[204.5,61.0],[243.6,61.0],[281.16,61.0],[315.3,61.0]] for indexs in entryCoordinate {

我是Swift新手,我正在使用2D数组进行比较,一旦条件为真,我需要获取行索引,但我得到了一个错误状态,
无法使用类型为(of:array)的参数列表调用索引。

我的代码:

var entryCoordinate: [[Float]] = [[130.6,61.0],[167.5,61.0],[204.5,61.0],[243.6,61.0],[281.16,61.0],[315.3,61.0]]

 for indexs in entryCoordinate
        {
            if indexs[0] == startPathPointX && indexs[1] == startPathPointY
            {
                let pathStartElement = indexs.index(of: indexs)
                print(pathStartElement)
            }

            if indexs[0] == endPathPointX && indexs[1] == endPathPointY
            {
                let pathEndElement = indexs.index(of: indexs)
                print(pathEndElement)
            }
        }

从使用
startPathPointY
endPathPointY
的代码中,您需要比较2D数组中的第二个对象,但您需要不断比较第一个对象,然后像这样与数组一起使用,以获得
pathStartElement
pathEndElement

if let pathStartElement = entryCoordinate.index(where: { $0[0] == startPathPointX && $0[1] == startPathPointY }) {
    print(pathStartElement)
}
if let pathEndElement = entryCoordinate.index(where: { $0[0] == endPathPointX && $0[1] == endPathPointY }) {
    print(pathEndElement)
}
请尝试以下代码:

let myIndexPathStartElement = self.arrImagetData.index(where: { $0[0] == startPathPointX && $0[1] == startPathPointY })

let myIndexPathEndElement = self.arrImagetData.index(where: { $0[0] == endPathPointX && $0[1] == endPathPointY })

indexs.index(of:indexs)
你的意思是
entryCoordinate.index(of:indexs)
,不是吗?否则,如果有重复的值,它应该只返回找到的第一个元素。另外
如果indexs[0]==startPathPointX&&indexs[1]==startPathPointY
,没有?如果找到,我想获取entryCoordinate的行索引…因此这就像获取entryCoordinate.enumerated()中(index,acordinade)的
值所在的行一样。{if acordinade[0]==startX&&acordinade[1]==startY{print(“CoordinateFound:\(acoordinade)”;打印(“索引:\(索引)”)}
而不是?对于从那里获取索引的循环: