Bird
0
0

In Swift, what does the exclamation mark (!) after a variable type indicate?

easy📝 Conceptual Q1 of 15
iOS Swift - Swift Language Essentials
In Swift, what does the exclamation mark (!) after a variable type indicate?
var username: String!
AA forced cast to another type
BA non-optional variable
CA constant value
DAn implicitly unwrapped Optional
Step-by-Step Solution
Solution:
  1. Step 1: Understand the syntax

    The exclamation mark (!) after a type in Swift declares an implicitly unwrapped Optional, which means it can hold a value or nil but is automatically unwrapped when accessed.
  2. Step 2: Differentiate from other options

    It is not a non-optional (B), constant (C), or a forced cast (D).
  3. Final Answer:

    An implicitly unwrapped Optional -> Option D
  4. Quick Check:

    Exclamation mark after type means implicitly unwrapped Optional [OK]
Quick Trick: Exclamation mark after type means implicitly unwrapped Optional [OK]
Common Mistakes:
  • Confusing ! after type with force unwrapping a variable
  • Assuming it's a non-optional type
  • Mixing it up with constants

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes