Internal structure(?) of optional mark

Hi, I'm studying optional and I have a simple question.

I'm just curious how the optional mark(? or !) is made.
For example,

Code Block swift
var test: Int?
var test: Int!

Those question and exclamation mark after Int are types?
How can I call those marks? Can I check a developer document or internal source about those?

Answered by OOPer in 631452022

As you said, I guess, Int? and Int! are kind of type aliases of Optional<Int>?

I'm not sure if type alias is the right term, but anyway, Int? is exactly the same as Optional<Int>.
Optionals are very often used in Swift, so it has a shortcut form.
`
Starting with the question mark, Int? is a short cur form of Optional<Int>.
Optional is an enum type, and Swift compiler has many builtin features to support Optionals.

The exclamation mark is a little bit more complicated.
Int! is equivalent to Optional<Int> as well as Int?. But Swift compiler adds some hidden attribute implicitly unwrapped to the variables declared using !.

How can I call those marks?

How to call depends on each person, but you can find some documents with Optional and Implicitly Unwrapped Optional.
The latter is sometimes abbreviated as IUO.

Can I check a developer document or internal source about those?

Documentation of enum type Optional is available in the doc of Swift Standard Library.
Optional

Swift compiler is open source and you can check the source of it in a GitHub repository.
https://github.com/apple/swift

But it may be very hard to find which parts of the compiler and the runtime code are for supporting Optionals.


Thanks for reply and some urls. I'll check it.

But I'm still wondering.
Maybe I questioned not enough because I'm studying English as well..Haha

Anyway what I meant is
I'd like to know how exclamation and question marks work with optional.

As you said, I guess, Int? and Int! are kind of type aliases of Optional<Int>?
My friend and I thought those marks are kind of functions or type aliases.
Accepted Answer

As you said, I guess, Int? and Int! are kind of type aliases of Optional<Int>?

I'm not sure if type alias is the right term, but anyway, Int? is exactly the same as Optional<Int>.
Optionals are very often used in Swift, so it has a shortcut form.
`
Internal structure(?) of optional mark
 
 
Q