Arrays ClosedInterval<;字符串>;用Swift[串]
为什么:Arrays ClosedInterval<;字符串>;用Swift[串],arrays,swift,string,Arrays,Swift,String,为什么: let i = 1...100 let s = [Int](i) 屈服 [1, 2, 3, ..., 100] Cannot invoke initializer for type '[String]' with an argument list of type '(ClosedInterval<String>)' true 但是 屈服 [1, 2, 3, ..., 100] Cannot invoke initializer for type '[String]
let i = 1...100
let s = [Int](i)
屈服
[1, 2, 3, ..., 100]
Cannot invoke initializer for type '[String]' with an argument list of type '(ClosedInterval<String>)'
true
但是
屈服
[1, 2, 3, ..., 100]
Cannot invoke initializer for type '[String]' with an argument list of type '(ClosedInterval<String>)'
true
屈服
[1, 2, 3, ..., 100]
Cannot invoke initializer for type '[String]' with an argument list of type '(ClosedInterval<String>)'
true
Int
符合ForwardIndexType
,因此在
let i = 1...100
let i = "a"..."z"
…
是操作员
public func ...<Pos : ForwardIndexType where Pos : Comparable>(start: Pos, end: Pos) -> Range<Pos>
public func ...<Bound : Comparable>(start: Bound, end: Bound) -> ClosedInterval<Bound>
…
是操作员
public func ...<Pos : ForwardIndexType where Pos : Comparable>(start: Pos, end: Pos) -> Range<Pos>
public func ...<Bound : Comparable>(start: Bound, end: Bound) -> ClosedInterval<Bound>
产生true
在Swift 3中,范围和间隔类型已重命名并
重组:
"1" ... "100" // CountableClosedRange<Int>
"a" ... "z" // ClosedRange<String>
结果是
["a", "b", "c", ... , "z"]
作为字符的数组
或字符串的数组