Creates a string representing the given value.
SDK
- Xcode 8.0+
Framework
- Swift Standard Library
Declaration
Discussion
Use this initializer to convert an instance of any type to its preferred representation as a String
instance. The initializer creates the string representation of instance
in one of the following ways, depending on its protocol conformance:
If
instance
conforms to theText
protocol, the result is obtained by callingOutput Streamable instance
on an empty string.write(to: s) s
.If
instance
conforms to theCustom
protocol, the result isString Convertible instance
..description If
instance
conforms to theCustom
protocol, the result isDebug String Convertible instance
..debug Description An unspecified result is supplied automatically by the Swift standard library.
For example, this custom Point
struct uses the default representation supplied by the standard library.
After adding Custom
conformance by implementing the description
property, Point
provides its own custom representation.