ios - 隐式解包的可选类型 - 可能有错字?

标签 ios swift

来自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/

相关文章:

iphone - iOS 开发 : After updating my iPhone 4 to iOS 4. 3 Beta 3,我的应用程序显示 "This game is not recognized by Game Center"

arrays - 从数组中添加子项

ios - 我应该如何在 Swift 中创建一个依赖于另一个变量的变量?

ios - 在同一文件中的 View Controller 之间以 Swift 传递数据

swift - 如何为初始选项卡栏 Controller 提供类名?

ios - 将 CIFilter 应用于视频文件并保存

ios - Swift 中的分割操作

ios - 从 AAC 数据创建 CMSampleBuffer

ios - 将 UITextfield 问题转换为 NSMutableArray

iphone - 如何让 UIWebView 加载网页,但 URL 在 UILabel 上?