来自Swift Programming Language文档:
Implicitly Unwrapped Optional Type
The Swift language defines the postfix ! as syntactic sugar for the named type ImplicitlyUnwrappedOptional, which is defined in the Swift standard library. In other words, the following two declarations are equivalent:
var implicitlyUnwrappedString: String! var implicitlyUnwrappedString: String!
In both cases, the variable implicitlyUnwrappedString is declared to have the type of an implicitly unwrapped optional string. Note that no whitespace may appear between the type and the !.
我错过了什么吗?这两行在我看来完全一样,为什么这两个声明不等同?
最佳答案
是的,这没有意义。您将在 Swift 书中找到正确的版本:
In other words, the following two declarations are equivalent:
var implicitlyUnwrappedString: String! var implicitlyUnwrappedString: ImplicitlyUnwrappedOptional<String>
摘自:Apple Inc.“The Swift Programming Language”。电子书。 https://itun.es/de/jEUH0.l
关于ios - 隐式解包的可选类型 - 可能有错字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29383098/