Below is from Apple doc on String
:
Writing to a File or URL
func write(String)
Appends the given string to this string.func write(to: inout Target)
Writes the string into the given output stream.
I wonder is it correct? These two APIs are defined in stdlib and, as far as I can tell, they have nothing to do with writing string to file or URL.
The correct APIs are defined in Foundation. Below are two examples of them:
extension StringProtocol {
/// Writes the contents of the `String` to a file at a given
/// path using a given encoding.
public func write<T>(toFile path: T, atomically useAuxiliaryFile: Bool, encoding enc: String.Encoding) throws where T : StringProtocol
/// Writes the contents of the `String` to the URL specified
/// by url using the specified encoding.
public func write(to url: URL, atomically useAuxiliaryFile: Bool, encoding enc: String.Encoding) throws
}
Am I misunderstanding something?