The result changes when you import Foundation.
("\r\n").contains("\r") // false
("\r\n").contains("\n") // false
But:
import Foundation
("\r\n").contains("\r") // true
("\r\n").contains("\n") // true
(Tested in Xcode 11.5.1, Swift 5.2.4)
This is because String
implicitly imports NSString.contains(_:)
when you import Foundation, and the compiler prefers this over the generic Sequence.contains(_:)
method. And NSString
counts UTF-16 code units, not Character
s.