简体   繁体   中英

What is the difference between optional and implicitly unwrapped optional?

Consider these two declarations:

var implicitUnwrappedOptionalInt: Int! = nil

var optionalInt: Int? = nil

The result would be nil in both the cases. So what is the difference?

An implicitly unwrapped optional can be (will be) initialized nil BUT you are telling the compiler that it will be set to a value before you first use it. If you do try and use it before it is initialized like I do below, you will crash everytime.

在此处输入图片说明

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