Swift’s String type is bridged with Foundation’s NSString class. Foundation also extends String to expose methods defined by NSString. This means, if you import Foundation, you can access those NSString methods on String without casting.
For more information about using String with Foundation and Cocoa, see Bridging Between String and NSString.
As I understood, this code regarding the doc should works:
import Foundation
class A {
func doSome() {
"".isEqual(to: "q")
}
}
But it doesn't.
I've asked at stackoverflow but I didn't find a proper explanation.
This is probably a compiler bug when trying to resolve the method (it finds a method with the same name on String and so don't fallback to looking for NSString methods).
Other foundation methods without matching String method work as documented:
import Foundation
func foo() {
"".caseInsensitiveCompare("q")
}
I just tested what was inside the note. It was interesting to check it.There is no reason to use them. It confuses: you can use. You are right: there is no “you can use all “, but there is no “you can use a part of them” too.
"Foundation also extends String to expose methods defined by NSString. This means, if you import Foundation, you can access those NSString methods on String without casting.”
If “methods defined by NSString” really means “some methods defined by NSString” it should be corrected to say just that.