2 ms·
I'm curious, if my variable "a" is indeed null, and when I say a!, what will happen? will it be a runtime error? like a memory access violation in c++? what's
by billconan 11y ago
I'm curious, if my variable "a" is indeed null, and when I say a!, what will happen?
will it be a runtime error? like a memory access violation in c++?
what's the benefit of adding !? if it generates the same access violation runtime error?
- rockshassa 11y agoyes, it is a runtime error. given the code let foo = bar! If bar is nil, you'll get a runtime error "unexpectedly found nil when unwrapping bar" in my opinion, the benefit of optionals in general is that it allows you to guarantee at compile time that certain variables (non optionals) will _never_ be nil, which enables all kinds of compiler optimizations.