Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/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
Swift 数组索引(of:)方法签名返回Int?但使用上述方法返回Array.Index?_Swift - Fatal编程技术网

Swift 数组索引(of:)方法签名返回Int?但使用上述方法返回Array.Index?

Swift 数组索引(of:)方法签名返回Int?但使用上述方法返回Array.Index?,swift,Swift,在苹果的文档中,索引(of:)签名显示返回类型为Int?: func索引(元素:元素)->Int 但是,在下面的示例中,i的类型是Array.Index? let arr = [1,2,3,4,5] var i = arr.index(of: 4) // i is Array.Index? 为什么退货类型不同?他们是同一个人吗?我在这里遗漏了什么?Array.Index是Int;)啊,我现在明白了。这是一个打字机别名。但是为什么呢?不太清楚为什么是什么意思–集合需要索引关联类型,Array通

在苹果的文档中,
索引(of:)
签名显示返回类型为
Int?

func索引(元素:元素)->Int

但是,在下面的示例中,
i
的类型是
Array.Index?

let arr = [1,2,3,4,5]

var i = arr.index(of: 4) // i is Array.Index?

为什么退货类型不同?他们是同一个人吗?我在这里遗漏了什么?

Array.Index
Int
;)啊,我现在明白了。这是一个打字机别名。但是为什么呢?不太清楚为什么是什么意思–
集合
需要
索引
关联类型
Array
通过
Int
@Aaron满足了这一点,因为
集合
协议要求其一致性类型使用
Int
作为其索引将受到不必要的限制。如果我想用我自己的
Int128
索引大于
Int
Int64
)可以索引的集合,该怎么办?@Alexander更具体地说,
index
为什么应该是一个数字<代码>字典也是集合!