Nullable and Non-Nullable types
suggest changeNormal types, like String
, are not nullable. To make them able to hold null values, you have to explicitly denote that by putting a ?
behind them: String?
var string : String = "Hello World!"
var nullableString: String? = null
string = nullableString // Compiler error: Can't assign nullable to non-nullable type.
nullableString = string // This will work however!
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents