简体   繁体   中英

Implicitly Unwrapped Optional Types - Possible Typo?

From the Swift Programming Language documentation:

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 !.

Am I missing something? Both lines look exactly the same to me, why wouldn't the two declarations be equivalent?

Yes, that makes no sense. You'll find the correct version in the Swift book:

In other words, the following two declarations are equivalent:

 var​ ​implicitlyUnwrappedString​: ​String​! ​var​ ​implicitlyUnwrappedString​: ​ImplicitlyUnwrappedOptional​<​String​> 

Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/de/jEUH0.l

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM