Language/Swift

Swift - starts

codinglearn 2020. 7. 13. 10:30
반응형

starts(with:)

Returns a Boolean value indicating whether the initial elements of the sequence are the same as the elements in another sequence.

시퀀스의 초기 요소가 다른 시퀀스의 요소와 같은지 여부를 나타내는 부울 값을 반환한다.

 

func starts<PossiblePrefix>(with possiblePrefix: PossiblePrefix) 
-> Bool where PossiblePrefix : Sequence, Self.Element == PossiblePrefix.Element

 

let a = 1...3
let b = 1...10

print(b.starts(with: a))
// Prints "true"
print(b.starts(with: []))
// Prints "true"
반응형