Avatar ·

What does the exclamation mark (!) mean in Swift? Problem with optional types

Hi! I just started learning Swift and keep encountering the exclamation mark (!) in other people's code. For example, I've seen code like this:\n\n```swift\nvar name: String! = "Alice"\nprint(name!)\n\nlet array: [String?] = ["hello", nil, "world"]\nif let value = array.first {\n print(value!) // why is ! needed here?\n}\n```\n\nI understand it's somehow related to optional types (Optionals), but I'm confused. In some places I see a question mark (?), in others an exclamation mark (!).\n\nI was told that ! is "forced unwrapping," but I don't understand when it's safe to use. For example, if I write:\n\n```swift\nvar optionalNumber: Int? = nil\nlet number = optionalNumber! // app crash!\n```\n\nthe app crashes with an error. Why is such a dangerous op