I know what "?" and "!" mean when I declare variables in Swift. But what do they mean when using these variables? For example, in this code:
var attachment: NSTextAttachment = NSTextAttachment()
attachment.image = UIImage(named: "placeholder.png")
attachment.image!.size ... // or attachment.image?.size ...
attachment.image!.size if you're guaranteed that
nil. If you're wrong (and it is
nil) your app will crash. This is called forced unwrapping.
If you're not sure if it'll be
In your case
image! is OK, since you control whether
Read all of the documentation on Swift Optionals. It's a basic and fundamental part of the language.