I'm confused about the type requirements and declaration restrictions for Swift capture specifiers. The documentation says that weak
references must be var
and "of optional type", and that unowned
references must be of non-optional type. But Apple's own API reference has examples of unowned(unsafe)
references declared as optionals, while the Xcode interface builder creates weak
outlets and actions that are implicitly unwrapped (which is not always clearly "of optional type" in the language reference).
What types are required for each of the Swift capture specifiers? Which must be var
and which can be let
?
FWIW, I think its
weak
can beType?
orType!
, but notType
; and must bevar
unowned(safe)
(same asunowned
) must beType
; and may belet
unowned(unsafe)
can beType?
orType!
; and may belet
but I'm far from sure.