data(using:allowLossyConversion:)
- iOS
- 16.4+
- macOS
- 13.3+
- tvOS
- 16.4+
- watchOS
- 9.4+
func data(using encoding: String.Encoding, allowLossyConversion: Bool = false) -> Data?
func data(using encoding: String.Encoding, allowLossyConversion: Bool = false) -> Data?
sSS20FoundationEssentialsE4data5using20allowLossyConversionAA4DataVSgSSAAE8EncodingV_SbtF
What are these?8N75E
import Swift
import FoundationEssentials
@frozen struct String
A Unicode string value that is a collection of characters.
struct Encoding
@frozen struct Bool
A value type whose instances are either true
or false
.
@frozen struct Data
init(_ characters: Slice<AttributedString.CharacterView>)
init?<S>(bytes: S, encoding: String.Encoding) where S : Sequence, S.Element == UInt8
Creates a new string equivalent to the given bytes interpreted in the specified encoding. Note: This API does not interpret embedded nulls as termination of the string. Use String?(validatingCString:)
instead for null-terminated C strings.
init(contentsOf url: URL, encoding enc: String.Encoding) throws
Produces a string created by reading data from a given URL interpreted using a given encoding.
init(contentsOf url: URL, usedEncoding: inout String.Encoding) throws
Produces a string created by reading data from a given URL and returns by reference the encoding used to interpret the data.
init(contentsOfFile path: String, encoding enc: String.Encoding) throws
Produces a string created by reading data from the file at a given path interpreted using a given encoding.
init(contentsOfFile path: String, usedEncoding: inout String.Encoding) throws
Produces a string created by reading data from the file at a given path and returns by reference the encoding used to interpret the file.
init?(data: Data, encoding: String.Encoding)
Returns a String
initialized by converting given data
into Unicode characters using a given encoding
.
func withFileSystemRepresentation<R>(_ block: (UnsafePointer<CChar>?) throws -> R) rethrows -> R
func withMutableFileSystemRepresentation<R>(_ block: (UnsafeMutablePointer<CChar>?) throws -> R) rethrows -> R
struct CompareOptions
These options apply to the various search/find and comparison methods (except where noted).