string(forKey:)
Returns the string associated with the specified key.
Declaration
func string(forKey defaultName: String) -> String?Parameters
- defaultName:
The key to retrieve from the defaults database.
Return Value
The string associated with defaultName, or nil if the key isn’t present in the defaults database.
Discussion
This method automatically coerces certain types to equivalent strings. For example, it converts the integer 123 to the string “123”. If the key is present, but the method can’t use it to create an appropriate string, this method returns nil.
This returned string is immutable, even if you originally set the key to a mutable string.