Null object: Difference between revisions
Content added Content deleted
(added swift) |
|||
Line 1,079: | Line 1,079: | ||
<lang sml>case v of NONE => "unbound value" |
<lang sml>case v of NONE => "unbound value" |
||
| SOME _ => "bounded value"</lang> |
| SOME _ => "bounded value"</lang> |
||
=={{header|Swift}}== |
|||
The closest thing in Swift are optional types. |
|||
<lang swift>var opt : Int? = nil // use "nil" to represent no value |
|||
opt = 5 // or simply assign a value to the optional type</lang> |
|||
To deconstruct it, use <code>if let</code>: |
|||
<lang swift>if let v = opt { |
|||
println("There is some value: \(v)") |
|||
} else { |
|||
println("There is no value") |
|||
}</lang> |
|||
=={{header|Tcl}}== |
=={{header|Tcl}}== |