0

I knew the difference but what I am more concerned is about "difference in the optional declaration" of object between using question mark and exclamation mark.

khunshan
  • 2,662
  • 4
  • 28
  • 34

1 Answers1

2

Type? is a regular optional. It can contain a value or nil. Type! is an implicitly unwrapped optional. It's the same as a regular optional but is assumed that it has a value immediately after it is defined. Because of that, you don't need to unwrap an implicitly unwrapped optional each time you want to use it. Be careful though, because if it is nil and you try to use it, you will get a runtime error.

Connor Pearson
  • 63,902
  • 28
  • 145
  • 142
  • "but is assumed that it has a value immediately after it is defined" It is not "assumed to have a value". – newacct Aug 29 '14 at 19:56